Skip to content

Instantly share code, notes, and snippets.

@kocisov
Created March 28, 2018 14:41
Show Gist options
  • Save kocisov/60b448e0744eb90ca45b1c770e378f9d to your computer and use it in GitHub Desktop.
Save kocisov/60b448e0744eb90ca45b1c770e378f9d to your computer and use it in GitHub Desktop.
express or bust
// require your modules
var express = require('express')
var bodyParser = require('body-parser')
// create instance of express
var app = express()
// let app use body-parser
// this one is parsing application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// this one is parsing application/json
app.use(bodyParser.json())
// POST endpoint /form
app.post('/form', (req, res) => {
// log sent body
console.log(req.body)
// pass 'hello' back after request
res.send('hello')
})
// listen on port 3000
app.listen(3000, () => {
console.log('Running on *:3000')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment