Step 1 - Create a folder: mern-stack
Step 2 - Open vs code and press Ctrl + `, and then type npm init
Step 3 - Install Express - npm i express
Once the above steps are done,
Step 4 - create a folder with name backend: mern-stack/backend
Step 5 - Create a file: index.js and paste the below code :
index.js :
-------------
const express = require("express");
const app = express();
app.listen(5000, console.log("server started"));
Step 6 - Run the server
Go to cmd and type : node backend/index.js
and boom, your server is running at PORT 5000
Step 7 - Install Nodemon : npm install -g nodemon
Step 8 - Update package.json file :
{
"name": "y",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon backend/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
Now run the server : npm start
0 Comments