Getting Started with Node.js

Most of the work I do is on the client side, but thanks to the magic of Node.js, I’ve recently begun to dive into the world of server-side code. Node is framework and runtime environment for building server-side applications. It’s fast, event-driven, has huge ecosystem and best of all for me, it also happens to be built on Javascript.

What Makes Node Great

Node is great at serving requests. Traditional servers maintain a finite pool of threads for processing potential incoming connections. Each request temporarily occupies a thread before releasing it upon delivery of a response. Node avoids this by taking an asynchronous event-driven approach, so the server never waits for an API to return a response. Instead it uses an event notification mechanism to track pending calls, allowing the server to move through tasks quickly.

Setting Up the Basics

Node is available in pre made installer for Mac, Windows and Linux. Additionally you can compile it from the source code, if that’s your thing.

Once node is installed you can test it in the command line with a very simple test. Create a one line Javascript file containing a hello world statement. In this example I’ll make file.js with the following content:

console.log('where no one has gone before');

Now, from the command line, use the node command and specify the path to your file:

node file.js

If node is installed properly, what you should see is a console message printed inside your console window. You have successfully run Javascript code without a web browser.



Add a Comment

Your email address will not be published. Required fields are marked *