Created
January 20, 2019 19:01
-
-
Save funador/b7305bcfb55b34a624581cdfa4484b05 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require('dotenv').config() | |
const express = require('express') | |
const mongoose = require('mongoose') | |
const path = require('path') | |
const app = express() | |
const todoRouter = require('./todo/router') | |
// set public folder | |
app.use(express.static('public')) | |
// adding body parser for all routes | |
app.use(express.json()) | |
// route all calls to /api to todoRouter | |
app.use('/api', todoRouter) | |
// serve up our index.html page | |
app.get('/', (req, res) => { | |
res.sendFile(path.join(__dirname, '../public', 'index.html')) | |
}) | |
// connect the db and start the server | |
mongoose.connect(process.env.DB_URL, { useNewUrlParser: true }, () => { | |
app.listen(process.env.PORT || 8080, () => console.log('👍')) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment