Node.js is a free open-source server environment. It is a Javascript cross-platform runtime environment to build network applications in Windows, Mac OS, Linux, etc.

About Node.js:

  • An asynchronous event driven JavaScript runtime: When Node.js sends a request to the computer’s file system, it does not have to wait for the response to send the following request and many connections can be handled concurrently.
  • No locks. By using Node.js, dead-locking the process is not a worry as in thread-based networking. Therefore, we can reasonably develop scalable systems in Node.
  • Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Familiarity with Browser Javascript will help you become a Node pro in no time.
  • Unlike other popular web servers, Node.js is a cross-platform runtime environment. You can use it with Linux, Windows, Mac OS X, Unix, etc…

Learning the very basics of Node.js is great way to gain a profound understanding of how the back-end frameworks work, and how everything is fitting together. Therefore, we are adding Node.js as a required skill to complete our Fullstack Web Development guide.

Installation (Windows)

1. Go to https://nodejs.org/

Node.js.org

LTS or Current?
The most reliable and recommended approach is to use the LTS (Long Term Support) edition since it is usually the most stable version, and then upgrade when the LTS edition moves up.

2. Double click on the installer package that you have just downloaded and complete the straight forward install steps.

3. Let’s test Node.js by writing a simple Hello World example.

* Create a helloWorld.js file in the C:/examples/ folder for example. You can Create a .js file using Notepad++ or your favourite code editor:

You can copy and paste the code below:

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}/');
});

* Open the Command Prompt and navigate to the folder mentioned above.

* We need to initiate the file that we have just created. We can do so by writing node helloWorld.js and hit enter:

* Now go your browser and go to http://127.0.0.1:3000/

* Your computer is now a web server. It is listening to port 3000, and it will display a “Hello World” message if someone tries to access it on that port.

LEAVE A REPLY

Please enter your comment!
Please enter your name here