Skip to content

Instantly share code, notes, and snippets.

@romach
Last active October 11, 2020 19:58
Show Gist options
  • Save romach/7540861cdc834c941fcd2f4980a0523e to your computer and use it in GitHub Desktop.
Save romach/7540861cdc834c941fcd2f4980a0523e to your computer and use it in GitHub Desktop.
Add POST endpoint to express application
const express = require('express')
const bodyParser = require('body-parser')
// instantiate express application
const app = express()
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
// create POST route
app.post("/", (req, res) => {
const data = req.body.data;
res.send(data);
});
// start application
const PORT = 8080
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`)
})
{
"name": "express-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"body-parser": "^1.19.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment