var express = require('express'); var path = require('path'); var logger = require('morgan'); const http = require('http'); const hostname = '127.0.0.1'; const httpPort = 4080; var mongoose = require('mongoose'); var mongoDB = "mongodb://127.0.0.1/my_database"; mongoose.connect(mongoDB); mongoose.set('strictQuery', false); mongoose.Promise = global.Promise; var db = mongoose.connection; db.on('error', console.error.bind(console, 'MongoDB connection error:')); var app = express(); const httpServer = http.createServer(app); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'hbs'); app.use(logger('dev')); app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use(express.static(path.join(__dirname, 'public'))); var mainRouter = require('./routes/main'); var apiRouter = require('./routes/api/apiRouter'); app.use('/', mainRouter); app.use('/api', apiRouter); httpServer.listen(httpPort, () => { console.log(`Server running at http://${hostname}:${httpPort}/`); });