Skip to content
Snippets Groups Projects
Commit 79354ea7 authored by Nitesh Verma's avatar Nitesh Verma
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
# Ignore Node.js dependencies
node_modules/
# Ignore environment files
.env
\ No newline at end of file
This diff is collapsed.
{
"name": "express-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.21.2",
"nodemon": "^3.1.9"
}
}
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json()); // Middleware to parse JSON body
// get api path
app.get('/api/:pathParam', (req, res) => {
const pathParam = req.params.pathParam; // Path parameter
const queryParam = req.query.q; // Query parameter
res.json({
message: "Success",
pathParam,
queryParam
});
});
app.post('/api/data', (req, res) => {
const receivedData = req.body; // JSON body from request
res.json({
message: "Data received successfully",
receivedData: [receivedData] // Returning it as an array
});
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment