Node.js Tutorial: How JavaScript on the backend can make your life easier.

Node.js is JavaScript on the backend, built around the highly optimized google's V8 javascript engine. Welcome to the world of asynchronous non-blocking programming.

Node.js excels at:

  • High availability API's, the asynchronous model reduces the amount of processor time being wasted in idle while waiting for external resources to be processed.

  • Pub-Sub systems like a chat server using WebSockets through

  • High availability Proxy services.

  • Web Crawlers! Since Node.js is JavaScript on the server, you can do pretty cool stuff such as using a headless browser, through a tool like Puppeteer.

  • Develop desktop applications using Electron!

What Node isn't that good at:

  • Intensive processing on the server, if you have a task that you need to crunch, 9 times out of 10 there is a better tool around.

What you will learn#

By the end of this tutorial you will have a good grasp on the following:

  • How to use NPM, and understand how your Package.json file works

  • Understanding the basics of a Node.js application

  • Asynchronous programming using promises and the event loop

  • Building basic Node.js API using express

  • Using Node standard library, and the file system package

  • Try Catch error handling with Node

Prerequisites - What You Need To Know#

For this article, we assume that you're familiar with JavaScript basics, such as working with promises

For more on JavaScript, check out these interesting articles to enhance your grasp on the subject.

Step 0: Installing Node.js#

Node.js is available for most platforms.

If you are using brew on macOS you can install it as follows:

For Windows, Linux, macOS and other operating systems, you can download the Node binaries from here

Or you could use NodeSource to get your platform-specific binaries.

Step 1: Writing our Hello world with Node.js and understanding the basics of asynchronous programming.#

In an empty directory create a file named app.js with a single line of code as follows