Popular Tags

Node.js

Node.js is a server-side JavaScript run-time environment. JavaScript was always used as a client-side scripting language that adds functionality to websites and that runs inside a browser. But with Node.js you can use JS for server-side programming.


How to install Nodejs on your machine?

Check out the latest version of node.js or the more recommended LTS version and install it on your computer.


Web-server
Apache, nginx, and microsoft's IIS are currently the most used web servers on the web. But you can also use node for this kind of functionality. By simply installing node.js on your machine and creating http.js file like this:

var httpServer = require('http');

//create a server object
httpServer.createServer(function (request, response) {
  response.write('All in JS!'); //write a response to the client
  response.end(); //end the response
}).listen(80); //the server listens on port 80

The code above requires a http node module, creates a server and writes something to the response.

How to run your Node.js webserver?

node http.js

Now your server is listening on port 80.

To check if all is working correctly, just visit localhost (or 127.0.0.1) in your preferred browser.