-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.js
52 lines (43 loc) · 1.1 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.get('/', (req, res) => {
try {
const user = ['john', 'doe', 'jane', 'doe'];
res.status(200).json({
message: 'Hello World',
users: user
});
} catch (err) {
console.error(err);
res.status(500).json({
message: "Internal Server Error"
});
}
});
app.post('/user', (req, res) => {
try {
const user = req.body;
if (!user || !Array.isArray(user)) {
return res.status(400).json({
success: false,
message: 'User required!'
});
}
res.status(200).json({
success: true,
message: 'User created successfully',
user: user
});
} catch (err) {
console.error(err);
res.status(500).json({
message: "Internal Server Error"
});
}
});
app.listen(3000, () => {
console.log('App listening on port 3000');
});
module.exports = app;