Skip to content

Instantly share code, notes, and snippets.

@cziem
Created November 4, 2018 23:26
Show Gist options
  • Save cziem/a74ea5262067d0bdb85cbcff2d067098 to your computer and use it in GitHub Desktop.
Save cziem/a74ea5262067d0bdb85cbcff2d067098 to your computer and use it in GitHub Desktop.
minimal setup for the server.js
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const cors = require('cors')
require('dotenv').config()
const app = express()
const port = process.env.PORT || 5000
// Connect to the database
const options = { useNewUrlParser: true }
mongoose.connect('mongodb://localhost:/mern_boilerplate', options)
 .then(() => console.log('connected successfully'))
 .catch(err => console.log('An error occurred', err))
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.listen(port, () => console.log(`server is running on port ${port}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment