Created
March 28, 2018 14:41
-
-
Save kocisov/60b448e0744eb90ca45b1c770e378f9d to your computer and use it in GitHub Desktop.
express or bust
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 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