Whenever we are trying to fetch the data from our backend, the API is the point that helps us in doing that.
Let's create our first API :
Go to the index.js file and paste the below code :
index.js :
----------
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("API is running");
});
app.listen(5000, console.log("server started"));
Now run the server: npm start (which actually means: nodemon backend/index.js)
Setting up .env :
> create a file with name .env
> npm i dotenv
.env :
----------
PORT = 6000
index.js :
------------
const express = require("express");
const dotenv = require("dotenv"); //added
const app = express();
dotenv.config(); //added
app.get("/", (req, res) => {
res.send("API is running");
});
const PORT = process.env.PORT || 5000; //added
app.listen(PORT, console.log(`server started at ${PORT}`));
Setting up postman in VS CODE :
Just install thunder client in VS CODE
0 Comments