To create a project, create a folder and right click on it and click on "open with vscode".
Then, in the terminal of vscode type below commands.
npm init --yes
npm i express
After that create index.js and add below code to it.
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello");
});
app.get("/api/courses", (req, res) => {
res.send([1, 2, 3]); //courses array
});
app.listen(3000, () => console.log("listening"));
To run the code.
node index.js
In the browser, you can test the routes created.
http://localhost:3000/
http://localhost:3000/api/courses
No comments:
Post a Comment