-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (33 loc) · 716 Bytes
/
index.js
File metadata and controls
39 lines (33 loc) · 716 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
32
33
34
35
36
37
38
39
require("dotenv").config()
const express = require("express")
const bodyParser = require("body-parser")
const cors = require("cors")
const app = express()
const port = 8000
const models = require("./models")
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded())
app.get("/", (req, res) => {
res.send({
data: ""
})
})
app.get("/users", (req, res) => {
models.User.findAll()
.then(users => {
res.send({
data: users
})
})
.catch(error => {
res.status(400).send({
error: error
})
})
})
models.sequelize.sync().then(function() {
app.listen(port, err => {
console.log(`Server running at http://localhost:${port}`)
})
})