-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (32 loc) · 1.09 KB
/
index.js
File metadata and controls
39 lines (32 loc) · 1.09 KB
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
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const mongoose = require('mongoose');
const dotenv = require('dotenv')
const port = process.env.PORT || 3000
// Run before other code to make sure variables from .env are available
dotenv.config()
// database
mongoose.connect(process.env.MONGO_DB_URL, {useNewUrlParser: true});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
// we're connected!
});
// creating an express instance
const app = express()
// middleware
app.use(bodyParser.json())
app.use(cors())
// set up separate routes files for easier management
app.use(express.static('static'))
var resource = require('./routes/resource.js');
app.use('/resource', resource);
var restriction = require('./routes/restriction.js');
app.use('/restriction', restriction);
var availability = require('./routes/availability.js');
app.use('/availability', availability);
// run the server
app.listen(port, () => {
console.log(`Server running on port http://localhost:${port}`)
})