DEV Community

Cover image for Getting started with Nodejs/Express
Olumide Akinremi
Olumide Akinremi

Posted on

Getting started with Nodejs/Express

NodeJS is an open-source tools that runs on a JavaScript Engine and can be used to executes Javascript code outside a web browser.

Having worked with Nodejs, I can undoubtedly say that Nodejs is really an impressive tool and the community behind it is a massive one. Another interesting thing about NodeJS is that it is a backend cross platform Javascript runtime environment.

To get started with Nodejs we will cover the following:

  1. Introduction
  2. Setting up Node.js and NPM
  3. Example Project (writing hello world program)
  4. Installing a package

1. Introduction:
To get started, this is what you need to know.

_Nodejs is a JavaScript runtime built on Chrome’s V8 JavaScript engine._

NPM is the package manager for JavaScript and the world’s largest software registry which has over 350,000 packages.

Express.js is a Node.js web application server framework designed for building single-page, multi-page, and hybrid web applications.

2. Setting Up NodeJs:
NodeJS and NPM are two important tools you need to get started and luckily, you can get all in one box by downloading NodeJS. After downloading and installing it, run to code below to be sure that everything is properly installed

npm -v to know the version of npm you are running currently.

node -v to know the version of node you are running currently.

3. Example Project (writing hello world program)
Create a folder name node-hello-program on your desktop then open your terminal and run the code below and follow the prompt to generate the package.json file

npm init

run npm install express to install express

create a file called server.js and add the code below

const express = require ('express');

const app = express();

app.get('/', (req, res) => {
    return res.send('hello world');
});

app.listen(4000, () => {
    console.log('app listening on port 4000');
});
Enter fullscreen mode Exit fullscreen mode

run node server.js on your terminal to start the node server.

open your browser to see the changes on localhost:4000

Yay!

We are done, kindly drop your feedbacks and also share with your friends.

Thank you.

Top comments (0)