-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (21 loc) · 715 Bytes
/
Copy pathindex.js
File metadata and controls
25 lines (21 loc) · 715 Bytes
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
const express = require('express')
const app = express()
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(function(req, res, next){
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
next();
});
app.post('/ping', function (req, res) {
req.body.text = `${req.body.text} from Nodejs`;
res.send(req.body)
})
app.listen(3000, function (err) {
if (err) {
console.error('Failed to start server:', err.message)
process.exit(1)
}
console.log('Nodejs app listening on port 3000')
})