Vinit Parekh
VINIT PAREKH's Blog

VINIT PAREKH's Blog

Create Express.JS from Scratch

Vinit Parekh's photo
Vinit Parekh
·Apr 30, 2022·

1 min read

Create Express.JS from Scratch

Photo by Luca Bravo on Unsplash

In this article we are going to create simple express application so follow along with me

Step 1: Install nodejs from Node.JS on your system.
Step 2: After installation check the version of NodeJS to ensure that NodeJS is    installed or not.

node --v

Step 3: Create a folder for your app with the following command Go to that directory

mkdir my_app
cd my_app


Step 4: initialize NPM for your project by using npm init -y

Step 5: Install the express package from NPM.

npm i express

Step 5: create the index.js in your my_app directory

Step 6 Write the following code to create your backend application

const express = require('express');
const PORT = 3001 || process.env.PORT
const app = express()

app.get('/', (req, res) => {
    res.send("<h1>This is my first app</h1>")
})

app.listen(PORT, () => {
    console.log(`App is up and running on ${PORT}`);
})

Step 7: Search http://localhost:3001 on your tab bar of the browser.

Yey, First application has been created successfully and you will get an output like mentioned below

 
Share this