Skip to content

Instantly share code, notes, and snippets.

@DennisRas
Created March 18, 2018 21:09
Show Gist options
  • Save DennisRas/d28bab2992e05cd79cb7fdbb54b7bb51 to your computer and use it in GitHub Desktop.
Save DennisRas/d28bab2992e05cd79cb7fdbb54b7bb51 to your computer and use it in GitHub Desktop.
Express route-specific JSON response
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
// create application/json parser
var jsonParser = bodyParser.json()
app.post('/api/users', jsonParser, function (req, res) {
if (!req.body) return res.sendStatus(400)
res.json({foo: 'bar'})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment