Skip to content

Instantly share code, notes, and snippets.

@TechNinjaWeb
Created October 27, 2017 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TechNinjaWeb/3b6a7636714d6bebbbb54bd90feb369c to your computer and use it in GitHub Desktop.
Save TechNinjaWeb/3b6a7636714d6bebbbb54bd90feb369c to your computer and use it in GitHub Desktop.
Basic Express Server
const fs = require('fs')
const port = process.env.PORT || 5000
const express = require('express')
const app = express()
const http = require('http')
const bodyParser = require('body-parser')
const server = http.createServer(app)
const _ = require('lodash')
// Express App setup
app.use(express.static(__dirname))
app.use(bodyParser.json())
// Catch the test route
app.all(['/test'], function(req, res, next) {
res.send('testing')
})
// Catch all other routes
app.all(['*'], function(req, res, next){
res.send('ok')
})
// Begin server
server.listen(port, () => console.log(`App running on localhost:${port}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment