-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
58 lines (40 loc) · 1.39 KB
/
app.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env nodejs
// We’ll declare all our dependencies here
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const config = require('./config/database');
const genelist = require('./controllers/genelist');
//const cache = require('memory-cache');
//Connect mongoose to our database
mongoose.connect(config.database);
var db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error"));
db.once("open", function(callback) {
console.log("Connection succeeded.");
});
//Declaring Port
const port = 3003;
//const port = 3004;
//Initialize our app variable
const app = express();
//Middleware for CORS
app.use(cors());
//Middlewares for bodyparsing using both json and urlencoding
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
/*express.static is a built in middleware function to serve static files.
We are telling express server public folder is the place to look for the static files
*/
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req,res) => {
res.send("Invalid page");
})
//Routing all HTTP requests to /genelist to genelist controller
app.use('/genelist', genelist);
//Listen to port 3000
app.listen(port, () => {
console.log(`Starting the server at port ${port}`);
});