Learning Objective:
- In this article, you will learn to create a node js project and run the server.
Task 1: Create Project
mkdir project-api
cd project-api
npm init -y
Task 2: Install Dependencies
npm install express@next
npm install nodemon -D
"dependencies": {
"express": "^5.0.0-alpha.8"
},
"devDependencies": {
"nodemon": "^2.0.6"
}
Task 3: Create app.js
const express = require('express')
const app = express()
const port = 3000
app.listen(port, () => console.log(`Server is listening on port ${port}!`));
Task 4: Run the Server
nodemon app.js
D:\restapi-lab\project-api>nodemon app.js
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
Server is listening on port 3000!
Git Instructions
Git
git init
git status
git add package.json package-lock.json app.js
git status
git commit -m "Project Setup"
Summary
- Successfully, we have created the project and the server is running.