-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (27 loc) · 789 Bytes
/
server.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
const express = require('express')
const app = express()
const bodyParser = require("body-parser");
const mongoose = require('mongoose');
const user = require("./routes/api/user");
const profile = require('./routes/api/profile');
// connect mongodb
const db = require('./config/config').mongoURI;
mongoose
.connect(db)
.then(() => console.log(`mongodb connected on ${db}`))
.catch((err) => console.log(err));
// body-parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// test
app.get('/', function (req, res) {
res.send('Hello World')
});
// routes
app.use("/api/users", user);
app.use("/api/profile", profile);
const PORT = 5000;
// run server
app.listen(PORT, () => {
console.log(`server is running on port ${PORT}`);
});