How to Create and Run the Server in Express, Node and React JS?

How to Create and Run the Server in React JS

If you are in the client folder, go back on the root, run command – cd..

Run command: npm init -y

In package.json add – “type”:”module”

Create a folder in the root  “api”

Create a file in api folder “index.js”

Install express using below given command –

npm i express

write below given code in index.js –

import express from ‘express’
const app=express();
app.listen(3000, ()=>{
    console.log(‘Server is running on 3000 PORT’);
})

Install a package – npm i nodemon so that we should not re-start server again n again after making some changes. Using this package server will auto start.

Add a script in package.json –

“dev”: “nodemon api/index.js”,

“start” : “nodemon api/index.js”

 

Start the server – npm run dev

Tutorial Video – How to Create and Run the Server in React JS