forked from nanuchi/react-nodejs-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (25 loc) · 740 Bytes
/
server.js
File metadata and controls
31 lines (25 loc) · 740 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
26
27
28
29
30
31
const express = require('express');
const path = require('path');
const app = express(),
bodyParser = require("body-parser");
port = 3080;
// place holder for the data
const users = [];
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '../my-app/build')));
app.get('/api/users', (req, res) => {
console.log('api/users called!')
res.json(users);
});
app.post('/api/user', (req, res) => {
const user = req.body.user;
console.log('Adding user:::::', user);
users.push(user);
res.json("user addedd");
});
app.get('/', (req,res) => {
res.sendFile(path.join(__dirname, '../my-app/build/index.html'));
});
app.listen(port, () => {
console.log(`Server listening on the port::${port}`);
});