In the root directory: mkdir backend cd backend then type: npm init -y npm install express cors mongodb dotenv npm install -g nodemon write the following line in package.json after "main":"index.js" : "type":"module", Now, create server.js file inside backend folder. Write the following code in server.js file: // starts here import express from "express"; import cors from "cors" import restaurants from "./api/restaurants.route.js" const app = express(); app.use(cors()); app.use(express.json()); app.use("/api/v1/restaurants", restaurants); app.use("*",(req,res) => res.status(404).json({error: "Not found!"}) ); export default app; // ends here create .env file and write: RESTREVIEWS_DB_URI=mongodb+srv://ipritpritam:ipritpritam@cluster0.twcdr.mongodb.net/sample_restaurants?retryWrites=true&w=majority RESTREVIEWS_NS=sample_restaurants PORT=5000 then, create index.js in the backend ...
Deal With Errors. Happy coding