Skip to content
Snippets Groups Projects
Commit 832cc77a authored by Bhavyarani Suvarna's avatar Bhavyarani Suvarna
Browse files

express server creation

parent 1eb3bfc7
No related branches found
No related tags found
No related merge requests found
node_modules/
package-lock.json
Assignment2_step2.png

15.7 KiB

PostMethod_illustrate_using_CURL_Command.png

25.2 KiB

asignment2_step1.png

25.9 KiB

{
"dependencies": {
"express": "^4.21.2"
}
}
const express = require("express");
const app = express();
const port = 3000;
app.use(express.json());
app.get("/info/:pathParam", (req, res) => {
const pathParam = req.params.pathParam;
const queryParam = req.query.q;
res.json({
message: "GET API Response",
pathParam: pathParam,
queryParam: queryParam || "No query param provided"
});
});
app.post("/data", (req, res) => {
const receivedData = req.body;
res.json({
message: "POST API Response",
dataArray: Array.isArray(receivedData) ? receivedData : [receivedData]
});
});
app.listen(port, () => {
console.log(`Express Server is running on http://localhost:${port}`);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment