-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (32 loc) · 900 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Importing required modules
const express = require('express');
const bodyParser = require('body-parser');
// Importing products.json file
const products = require('./products.json');
// Create an instance of Express
const app = express();
const port = 3000;
// Configure middleware
app.use(bodyParser.json());
// Define GET endpoint at base URL '/'
app.get('/', (req, res) => {
res.send("Got a GET request at '/'");
});
// Define POST endpoint at base URL '/'
app.post('/', (req, res) => {
res.send("Got a POST request at '/'");
});
// Define POST endpoint at '/user'
app.post('/user', (req, res) => {
console.log(req.body);
res.send("Received");
const user = req.body;
});
// Define GET endpoint at '/products'
app.get('/products', (req, res) => {
res.send(products);
});
// Start the server
app.listen(port, () => {
console.log("Listening on PORT 3000");
});