forked from bbachi/angular-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) · 722 Bytes
/
Copy pathserver.js
File metadata and controls
31 lines (25 loc) · 722 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 app = express(),
bodyParser = require("body-parser");
port = process.env.PORT || 8080;
const users = [];
app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
app.use(express.static(process.cwd() + "/my-app/dist/angular-nodejs-example/"));
app.get('/api/users', (req, res) => {
res.json(users);
});
app.post('/api/user', (req, res) => {
const user = req.body.user;
users.push(user);
res.json("user addedd");
});
app.get('/', (req, res) => {
res.sendFile(process.cwd() + "/my-app/dist/angular-nodejs-example/index.html")
});
app.listen(port, (err) => {
if (err) {
console.log(err)
}
console.log(`Server listening on the port:!!!::${port}`);
});