-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (28 loc) · 922 Bytes
/
app.js
File metadata and controls
38 lines (28 loc) · 922 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
// app.js
require('dotenv').config(); // load env vars from .env file
const express = require('express');
const connectDB = require('./config/db');
const cors = require('cors');
// Setting PORT
const PORT = process.env.PORT;
// routes // add all of the routes in the API here
const bookRoute = require('./routes/books');
// import other routes...
// Start app
const app = express();
// Connect to MongoDB
connectDB();
// cors
app.use(cors());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// Init Middleware
app.use(express.json({ extended: false }));
app.get('/', (req, res) => res.send('Hello JV!'));
// use Routes
app.use('/api/books', bookRoute);
// ...more routes here...
app.listen(PORT, () => console.log(`Server is now running on port: ${PORT}`));