Created
September 16, 2019 19:10
-
-
Save artemis15/a1010b12cac73d1f8119353d8ccfa187 to your computer and use it in GitHub Desktop.
Confuration related to configure and start server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const mongoose = require("mongoose"); | |
const bodyParser = require("body-parser"); | |
let routes = require("../routes/routes"); | |
let server = express(); | |
let create = (config, db) => { | |
server.set("env", config.env); | |
server.set("port", config.port); | |
server.set("hostname", config.hostname); | |
// add middleware to parse the json | |
server.use(bodyParser.json()); | |
server.use( | |
bodyParser.urlencoded({ | |
extended: false | |
}) | |
); | |
//connect the database | |
mongoose.connect(db.database, { | |
useNewUrlParser: true, | |
useCreateIndex: true, | |
useUnifiedTopology: true | |
}); | |
routes.init(server); | |
}; | |
let start = () => { | |
let hostname = server.get("hostname"), | |
port = server.get("port"); | |
server.listen(port, function() { | |
console.log( | |
"Express server listening on - http://" + hostname + ":" + port | |
); | |
}); | |
}; | |
module.exports = { | |
create: create, | |
start: start | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment