Setup

  • STEP

    Step 1: download & install nodejs package

    Go to nodejs

    Step2: check version

    
    
                                node -v
                                npm -v
                            

    Step 3: Start Build Your Project

    
                            npm init
                            

    STEP 4: install express js

    
                            npm install express
                            

    Step 5: create server.js file

    
                            const express = require("express");
    
                            var app = express();
    
                            app.listen(5000, function () {
    
                                console.log("Started application on port %d", 5000);
    
                            });
    
                            

    Step 6: run

    
                            node server.js
                            

    Step 7 : npm start

    in package.json

    
                            {
                            "name": "node_app",
                            "version": "1.0.0",
                            "description": "1",
                            "main": "index.js",
                            "scripts": {
                                "test": "echo \"Error: no test specified\" && exit 1",
                                "start" : "node server.js"
                            },
                            "author": "",
                            "license": "ISC",
                            "dependencies": {
                                "express": "^4.18.1"
                            }
                            }
    
                            

    run

    
                                npm start 
                        

    Step 8: send response to web

    
                        const express = require('express');
    
                        const app = express();
                        const PORT = 3000;
    
                        app.get('/', (req, res)=>{
                            res.status(200);
                            res.send("Welcome to root URL of Server");
                        });
    
                        app.listen(PORT, (error) =>{
                            if(!error)
                                console.log("Server is Successfully Running, and App is listening on port "+ PORT)
                            else
                                console.log("Error occurred, server can't start", error);
                            }
                        );