Last active
October 11, 2020 19:58
-
-
Save romach/7540861cdc834c941fcd2f4980a0523e to your computer and use it in GitHub Desktop.
Add POST endpoint to express application
This file contains 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
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}`) | |
}) |
This file contains 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
{ | |
"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