Introduction to Node.js
Tags: node, javascript, programming, tutorial
Published: 2021-06-20 17:17:54

**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](https://nodejs.org/)

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

![Node.js - JavaScript Runtime](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjm1wsvoouuf3961waot.jpg)

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:

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

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](https://nodejs.dev/learn) for a more comprehensive guide to getting started with Node.js.

###Here's the Node.js timeline so far:
*(source: [nodejs.dev] (https://nodejs.dev/learn/a-brief-history-of-nodejs))*

####2009
+ Node.js is born
+ The first form of [npm](https://www.npmjs.com/) is created

####2010
+ [Express](https://expressjs.com/) is born
+ [Socket.io](https://socket.io/) is born

####2011
+ npm hits version 1.0
+ Larger companies start adopting Node.js: LinkedIn, Uber, etc.
+ [hapi](https://hapijs.com/) is born

####2012
+ Adoption continues very rapidly

####2013
+ First big blogging platform using Node.js: [Ghost](https://ghost.org/)
+ [Koa](https://koajs.com/) is born

####2014
+ The Big Fork: [io.js](https://iojs.org/) is a major fork of Node.js, with the goal of introducing ES6 support and moving faster

####2015
+ The [Node.js Foundation](https://foundation.nodejs.org/) 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
+ The [leftpad incident](https://blog.npmjs.org/post/141577284765/kik-left-pad-and-npm)
+ [Yarn](https://yarnpkg.com/en/) is born
+ Node.js 6

####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](https://nodejs.org/api/esm.html).mjs experimental support
+ Node.js 11

####2019
+ Node.js 12
+ Node.js 13

####2020
+ Node.js 14
+ Node.js 15

####2021
+ Node.js 16