I am running Visual Studio 2017 Community with a Solution that has multiple projects. One of which is the Angular SPA with Core 2. In the Angular SPA project, if I run the command from the package command (with the SPA project being selected from the dropdown);
npm install
I get the error;
WARN saveError ENOENT: no such file or directory, open 'C:\Users\matt\Source\Repos\project\Project\package.json'
which makes sense as the project is actually
'C:\Users\matt\Source\Repos\project\Project\AngularSPA\package.json'
If I then right click the package.json and run the update packages command from the solution explorer, the node_modules folder with the npm packages is being installed to the parent directory too? i.e.
'C:\Users\matt\Source\Repos\project\Project'
Instead of
'C:\Users\matt\Source\Repos\project\Project\AngularSPA'
am I doing something wrong and is there a setting I should change here? (As I can copy the folder back to the AngularSPA folder but this seems a bit of a hack?
The reason is that you start nmp intsall either from NuGet Package Manager Console or from built-in VS2019 Command Line -> Developer Command Prompt. Both bring solution directory as a npm working directory while you need a project directory.
There is a simple way to add a command prompt with the project directory as a working directory by adding Command Prompt as an external tool and select Project directory as Initial directory. More details are here
Related
I am running a React project and npm install installs all of the modules in the root folder of the project, in which it creates around 30 000 new files, which then slows dows web cloud syncing (I am unable to exclude locations). How can I install this large directory at a different location, that is outside the project folder or maybe globally somehow?
I have tried npm install -g after deleting the node_modules folder, but that said that everything is up to date and npm list -g shows only one item, that is the project. After that running npm start does not work, gives error 'react-scripts' is not recognized as an internal or external command
Learn Next JS and try to make server side rendering
I am running on windows.
My module is install via npm install. It's located in the node_modules which was locally created at my project.
For some reason, all of a sudden node has stop recognizing my module, even though it is installed and located in the root/node_modules location!!
I have tried every thing I could find online. What is going on???
tried clearing npm's cache
kill node.js process
re-open my command-line
even restarted my PC!!
path is configured correctly
One more thing:
if i manually install the package via: npm install --save my-module
its recognizing my package.
EDIT
I have noticed that when I run npm install it does not create the node_modules/.bin folder as of when I run npm install --save my-module it does create it.
EDIT 2
When manually placing my packages in the .bin folder than it works
Note, that you can also execute an installed npm module using the npx (Node.js Package Runner), which is part of npm.
npx my-module
You should see the module executable in ./node_modules/.bin
Please, at first re-install your node and shutdown your PC for 5 at least mins.
You can follow the following steps:
Search environment variables from start menu's search box.
Click it then go to Environment Variables
Click PATH
click Edit
Click New and try to copy and paste your path for 'bin' folder [find where you installed the node] for example according to my machine 'C:\Program Files\nodejs\node_modules\npm\bin'
If you got any error. try the another step:
Click New, then browse for the 'bin' folder
I've encountered a weird issue when installing Gulp in a new project.
Let's say I have the following path:
c:/development/myproject
When I run npm install gulp in that directory, the node_modules folder actually gets created in
c:/development/node_modules
instead of
c:/development/myproject/node_modules
And all of gulp plugins also get installed in that directory outside my project root.
I also have an earlier project where gulp was already installed before, and when I tried to rerun gulp installation in that project directory it was installed correctly in the project root (for example: c:/development/myolderproject/node_modules), not outside.
I don't think it has anything to do with the case, but the new project is using Laravel 4, while the other one is on Laravel 5.
I don't recall having to set any specific configuration before, so I'm totally confused why it behaves differently.
When you did npm install it found package.json from parent directory and thought it was the package root.
Related docs: https://www.npmjs.org/doc/files/npm-folders.html#more-information
Starting at the $PWD, npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective "current directory" for the purpose of running npm commands. (This behavior is inspired by and similar to git's .git-folder seeking logic when running git commands in a working dir.)
If no package root is found, then the current folder is used.
I run Ubuntu 15 and I had a similar issue where gulp was installing the node_module folder somewhere I couldn't find. gulp would say ../../node_modules was the location but it was NOT in my project folder.
I figured out from the link above and some more research I just needed to run npm init to create a project.json in my project folder. gulp was installing the node_modules in another folder because it searches for a project.json file to install the folder node_modules into.
Hope this helps anyone else solve this silly problem.
I have Node.js for windows installed the recommended way npm, using the global flag:
npm install -g node-windows
The next step is to run in your project root:
npm link node-windows
Do I create the project folder in the directory where I have node.js installed? (C:\Program Files\nodejs)
My Goal is to use node.js to send push notifications. I believe if I create the project directory(folder) in the correct spot all I have to do put the files I want to execute in the project directory and everything should work OK?
You can create a project folder anywhere. In the commandline you locate your folder:
C:\>cd "Users\Me\Documents\NodeJs\Projects\WebServer\"
Then just run node on any script you wish to startup.
C:\Users\Me\Documents\NodeJs\Projects\WebServer\>node startupscript.js
I am new to node.js. I downloaded and install node.js installer from the official site. I have added this installer folder in PATH environment variable and I am able to run programs. But when I try to install some package using npm in node console it shows the error npm should be run outside of the node repl, in your normal shell. I also tried it on a separate console. But it shows command not found though I have added node in the environment variable.
For Windows users, run npm commands from the Command Prompt (cmd.exe), not Node.Js (node.exe). So your "normal shell" is cmd.exe. (I agree this message can be confusing for a Windows, Node newbie.)
By the way, the Node.js Command Prompt is actually just an easy shortcut to cmd.exe.
Below is an example screenshot for installing grunt from cmd.exe:
Do not run the application using node.js icon.
Go to All Programmes->Node.js->Node.js command prompt.
Below is example screen shot.
If you're like me running in a restricted environment without administrative privileges, that means your only way to get node up and running is to grab the executable (node.exe) without using the installer. You also cannot change the path variable which makes it that much more challenging.
Here's what I did (for Windows)
Throw node.exe into its own folder (Downloaded the node.exe stand-alone )
Grab an NPM release zip off of github: https://github.com/npm/npm/releases
Create a folder named: node_modules in the node.exe folder
Extract the NPM zip into the node_modules folder
Make sure the top most folder is named npm (remove any of the versioning on the npm folder name ie: npm-2.12.1 --> npm)
Copy npm.cmd out of the npm/bin folder into the top most folder with node.exe
Open a command prompt to the node.exe directory (shift right-click "Open command window here")
Now you will be able to run your npm installers via:
npm install -g express
Running the installers through npm will now auto install packages where they need to be located (node_modules and the root)
Don't forget you will not be able to set the path variable if you do not have proper permissions. So your best route is to open a command prompt in the node.exe directory (shift right-click "Open command window here")
It's better to use the actual (msi) installer from nodejs.org instead of downloading the node executable only. The installer includes npm and makes it easier to manage your node installation. There is an installer for both 32-bit and 64-bit Windows.
Also a couple of other tidbits:
Installing modules globally doesn't do what you might expect. The only modules you should install globally (the -g flag in npm) are ones that install commands. So to install Express you would just do npm install express and that will install Express to your current working directory. If you were instead looking for the Express project generator (command), you need to do npm install -g express-generator for Express 4.
You can use node anywhere from your command prompt to execute scripts. For example if you have already written a separate script: node foo.js. Or you can open up the REPL (as you've already found out) by just selecting the node.js (start menu) shortcut or by just typing node in a command prompt.
As mscdex said NPM comes with the nodejs msi installed file. I happened to just install the node js installer (standalone). To separately add NPM I followed following step
Download the latest zip file of NPM from here.
Extract it in the same file as that of node js installer.
If you have added the directory containing to node js installer to PATH env variable then now even npm should be a recognized command.
you just open command prompt,
then enter in c:/>('cd../../')
then npm install -g cordova
It's simple. Press the Windows logo on your keyboard. Then, type node.js command prompt in the search bar and run it.
You must get directory right path of program(node.js in program files).
such as
and use "npm install -g phonegap"
Just open Node.js commmand promt as run as administrator