Skip to content

Instantly share code, notes, and snippets.

@funador
Created January 20, 2019 19:01
Show Gist options
  • Save funador/b7305bcfb55b34a624581cdfa4484b05 to your computer and use it in GitHub Desktop.
Save funador/b7305bcfb55b34a624581cdfa4484b05 to your computer and use it in GitHub Desktop.
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