What is Node.js?

SAAD ZAKAULLAH AHMAD
3 min readApr 20, 2020

Node.js is one of the platforms for executing JavaScript code at the server end. I chose it for Backend because it uses JavaScript which I have already learned earlier. Twitter, Uber, ebay etc. use Node.js for backend.

I will be using Node on Hyper Terminal (a command line interface). In the starting we will be in the “root” which is denoted by “/”. This can be verified by typing pwd (present working directory) in the terminal.

If you want to know more about the hyper terminal and how it works, then click here.

Node can be used to run the code that we have written(most likely in a text editor like VS Code) directly in the hyper terminal without going to the browser again and again.

The Node REPL ( Read Evaluation Print Loop)

It enables us to execute the code inside the editor.

To exit REPL, press Ctrl+C.

Node comes with a plenty of modules or libraries which can be used in order to save time for us to write codes repeatedly. For example, the fs (file system)module. In order to access the module, it must be “required”.

const fs = require(“fs”);

Now that we have the access to the file system module, there is a plenty of things which we can do with it like opening a file, reading and writing data in file, copy and manipulate local files, etc.

NPM (Node Package Manager)

NPM is a “package” of codes written by others to save our time so that instead of writing the codes again and again, we can use these packages. NPM is bundled with node. To initialise NPM, type:

npm init

Initialising NPM would open a file named package.json in your editor. We can also install external packages from NPM website (say car names) which would then show up here in package.json . After installing any of the packages, we will find that in the package.json file, we’ll have one more dependency. To access the random car name, following code should be followed in the editor:

var carNames = require('car-names');

var allNames = carNames.all;

var randomName = carNames.random();

In the terminal, to get the car name as output, type:

node index.js

//index.js is the filename in which you are writing your code.

This will generate some random car names in the terminal.

Thanks for reading. If you liked the blog, give it a 👏.

Would love to hear from you at saadahmad728@hotmail.com

--

--

SAAD ZAKAULLAH AHMAD

A web developer, mechanical engineer and an eternal learner.