Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

It seems like the website automatically recommend the most appropriate one by the operating system. Because my machine is windows, it recommends me to install x86 version of node.js.

If you installation is perfect, let us run below simple node.js code which can make your pc into simple web server.

Code Block
languagejs
titlesample.js
const http = require('http');
 
const hostname = '127.0.0.1';
const port = 3000;
 
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});
 
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Once you created above js code as "sample.js", you can run it like below command:

Code Block
node sample.js

You can check it on your browser at http://127.0.0.1:3000 and its result will be like below:

Image Added