-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (19 loc) · 757 Bytes
/
Copy pathapp.js
File metadata and controls
25 lines (19 loc) · 757 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
const express = require('express');
const mongoose = require("mongoose");
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 3000;
const www = process.env.WWW || './';
const db = mongoose.connect('mongodb://localhost/bookAPI');
const Book = require('./model/bookModel');
const bookRouter = require('./routes/bookRouter')(Book);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(www));
app.use('/api', bookRouter);
app.get('*', (req, res) => {
res.send('Welcome to Api');
// res.sendFile(`index.html`, { root: www });
});
// eslint-disable-next-line no-console
app.listen(port, () => console.log(`listening on http://localhost:${port}`));