Skip to content

Instantly share code, notes, and snippets.

@artemis15
Created September 16, 2019 19:10
Show Gist options
  • Save artemis15/a1010b12cac73d1f8119353d8ccfa187 to your computer and use it in GitHub Desktop.
Save artemis15/a1010b12cac73d1f8119353d8ccfa187 to your computer and use it in GitHub Desktop.
Confuration related to configure and start server
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