DEV Community

Cover image for Introduction to Node.js
Kasun Perera
Kasun Perera

Posted on • Updated on

Introduction to Node.js

Node.js is a runtime environment for executing JavaScript code outside of a browser.

Before Node.js, JavaScript has long been used in web pages and run only by browsers. But now we can execute JavaScript code without a browser with the help of Node.js which is built on Chrome’s V8 JavaScript engine.

Here’s a formal definition as given on the nodejs.org

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

Node.js - JavaScript Runtime

Node is ideal for building highly scalable, data-intensive, and real-time back-end services.

What's so special about Node.js?

  • Node.js is easy to get started and can be used for prototyping and agile development.

  • JavaScript everywhere. If you're a front-end developer who knows JavaScript, you can easily get started Node.js without learning a new programming language.

  • It also can be used for building superfast & highly scalable services. Node is used in production by large companies like Netflix, Uber, PayPal &, etc.

  • Node.js has the largest ecosystem of open-source libraries. There're a lot of free open source libraries out there that we can use to build our services.

Simple Node.js program.

First install node on your machine. There are many tutorials online to guide the installation based on your operating system.

Once you have installed Node.js, Create a file named server.js containing the following contents:

const http = require('http');

const hostname = '127.0.0.1';
const port = 3002;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Enter fullscreen mode Exit fullscreen mode

Now open your terminal, change the directory to the folder where the file is saved and run node server.js to start your web server.

Now, visit http://localhost:3002 and you will see a message saying "Hello World".

Cool! you’ve just written Hello World in Node.js.

Refer official documentation for a more comprehensive guide to getting started with Node.js.

Here's the Node.js timeline so far:

(source: nodejs.dev)

2009

  • Node.js is born
  • The first form of npm is created

2010

2011

  • npm hits version 1.0
  • Larger companies start adopting Node.js: LinkedIn, Uber, etc.
  • hapi is born

2012

  • Adoption continues very rapidly

2013

  • First big blogging platform using Node.js: Ghost
  • Koa is born

2014

  • The Big Fork: io.js is a major fork of Node.js, with the goal of introducing ES6 support and moving faster

2015

  • The Node.js Foundation is born
  • IO.js is merged back into Node.js
  • npm introduces private modules
  • Node.js 4 (versions 1, 2 and 3 never previously released)

2016

2017

  • npm focuses more on security
  • Node.js 8
  • HTTP/2
  • V8 introduces Node.js in its testing suite, officially making Node.js a target for the JS engine, in addition to Chrome
  • 3 billion npm downloads every week

2018

  • Node.js 10
  • ES modules.mjs experimental support
  • Node.js 11

2019

  • Node.js 12
  • Node.js 13

2020

  • Node.js 14
  • Node.js 15

2021

  • Node.js 16

Top comments (0)