Home windows How to run a Node.js application

How to run a Node.js application

Author

Date

Category

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:

  1. Opening the console cmd
  2. Go to the folder Z: \ home \ localhost \ www \ server with the command cd Z: \ home \ localhost \ www \ server
  3. Starting the server node server.js

Answer 2, authority 40%

  1. Install NodeJS
  2. Create the mywebserver.js file
  3. 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, '} /');
    });
    
  4. Right click mywebserver.js with Node.js

  5. 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

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions