-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (23 loc) · 707 Bytes
/
index.js
File metadata and controls
30 lines (23 loc) · 707 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
const express = require('express')
const app = express()
const connectDB = require('./db/connect')
const notFound = require('./middleware/not-found')
const authRoute = require('./routes/auth')
const protectedRoutes = require('./routes/protected')
require('dotenv').config()
const port = process.env.PORT || 3000;
// middleware
app.use(express.json())
// Routes
app.use('/api/user', authRoute);
app.use('/api/protected', protectedRoutes); // just for example
app.use(notFound)
const start = async () => {
try {
await connectDB(process.env.MONGO_URI);
app.listen(port, console.log(`Server listening on port ${port}...`))
} catch (err) {
console.log(err);
}
}
start()