How to run server.js
using node? node.exe
is located in C: \ Program Files \ nodejs
. And server.js
is located in Z: \ home \ localhost \ www \ server
Answer 1, authority 100%
If you installed NodeJS using the standard installer from the official site, then like this:
- Opening the console cmd
- Go to the folder
Z: \ home \ localhost \ www \ server
with the commandcd Z: \ home \ localhost \ www \ server
- Starting the server
node server.js
Answer 2, authority 40%
- Install NodeJS
- Create the mywebserver.js file
-
Add to content mywebserver.js
const http = require ('http'); const hostname = 'localhost'; const port = 8080; http.createServer ((req, res) = & gt; { res.writeHead (200, {'Content-Type': 'text / plain'}); res.end ('Hello World \ n'); }). listen (port, hostname, () = & gt; { console.log ('Server running at http: // $ {', hostname, '}: $ {', port, '} /'); });
-
Right click mywebserver.js with Node.js
- Open the link in a browser http: // localhost: 8080 /
Answer 3, authority 20%
1. Install nodeJS
2. run cmd and enter node --version, there should be displayed information about the version of the nodes, if there is, then you have installed the node correctly
3. go to the directory where your server.js script is located:
& gt; cd Z: \ home \ localhost \ www \
& gt; node server.js
PS: but it’s still better to install Linux (which I did recently;)), it is more convenient to work with the terminal there. you can install Linux as a second OS)
Answer 4
Try to run the server.js executable file through the context menu. Right button ->Open with ->And select Node. Server runnig at http://127.0.0.1:8124/ should appear on the command line. And then type this address into the browser.
Answer 5
Register the PATH variable, if it is not registered, go to the folder with server.js, and then start node server.js there.
Answer 6
C: \ Program Files \ nodejs \ node.exe Z: \ home \ localhost \ www \ server \ server.js