Setup a basic node express app

Posted on Jan. 6, 2020
express
nodejs
790

Steps

  • install node and npm
  • initialize the project with npm init
  • install required packages
  • implement the code & run

npm init

will ask for few details and fill those

after that a package.json will be created to maintain the packages & versions which will be required to our app

after installing npm install express my package.json looks like this

{
  "name": "express_sample",
  "version": "1.0.0",
  "description": "my sample app",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "N Kishore",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  }
}

so in my main index.js I have added the very basic code like below.

const express = require('express')

const app = express()

app.listen(3000, ()=>{
    console.log('Server is up on 3000')
})

 

and then open up your terminal and go to your project directory and then run the below command to start the server.

node index.js

Go to your browser and open http://localhost:3000 to check the server is up and running.

Next start adding more routes and modules based on requirement.




0 comments

Please log in to leave a comment.