Last active
November 21, 2018 22:36
-
-
Save MBehtemam/35f3fc9d5eaa1b724f4e1e17ea8fa1aa to your computer and use it in GitHub Desktop.
Sample server
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
const express = require("express"); | |
const bodyParser = require("body-parser"); | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
app.get("/", (req, res) => { | |
res.json({ hope: "loop" }); | |
}); | |
app.post("/", (req, res) => { | |
const { name } = req.body; | |
if (!name || name === undefined) { | |
res.sendStatus(400); | |
} else { | |
res.json({ input: name }); | |
} | |
}); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment