Where should I create project folders for node.js? - node.js

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

Related

How to install node modules to a folder outside the project folder?

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

Visual Studio npm install saving node_modules to solution folder

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

how can I open web application requiring node.js

I must run micro-crawler https://github.com/WebMole/Micro-Crawler which is a crawler web application, that run with node.js.
I could not figure out how to open this app, I download node.js, and when I write install npm and install bower to the node.js command line nothing happened. Also I did not understand how to start web applicaion after installations
Please help me
Finally I solved the issue
First, I install node.js, then move node.js folder to wampserver directory,
and move the web sites files in the node.js directory
Second, I go to the path where node.js is from command line, then enter "install npm" command
line
The error appeared in this phase for solving I create a npm
folder in c:users/user_name_of_your_computer/app_data/roaming then I installed git and enter the directories of bin and cmd files of git to the system enviroments/path
Third I enter the commands "bower install" and "npm install -g grunt-cli" from the comand. from the path of where node.js is
and the micro-crawler works
Did you execute your .js file? You can do that with node.js cli thus:
path/to/your/file: node file.js
This is a good reference:
How to run a hello.js file in Node.js on windows?

What location does Node.js needs to be installed

I am trying to setup a project to work with Grunt. I need to install Node.js for that to run. I have downloaded and installed Node.js in c:\programfiles.
However when I try running npm install in my project c:\Grunt-proj , I get an error 'npm' is not recognized as an internal or external command.
Can someone help me with where to install Node.js? I am trying to follow this tutorial-
http://24ways.org/2013/grunt-is-not-weird-and-hard/
Many thanks,
The location is fine. I also have installed it in Program Files. But if you need to run the command npm from a command prompt then you need to add it to the path of the system. In my case I have C:\Program Files\nodejs

How to resolve 'npm should be run outside of the node repl, in your normal shell'

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

Resources