-
-
Save sempostma/b857681ec535d998511d42bcf63c0139 to your computer and use it in GitHub Desktop.
HTTP echo server using node.js and express
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": "mock-http-server", | |
"version": "1.0.0", | |
"description": "", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"body-parser": "^1.19.0", | |
"express": "^4.17.1" | |
} | |
} |
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
var express = require('express'); | |
var http = require('http'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
app.use(bodyParser.text({ | |
type: function(req) { | |
return 'text'; | |
} | |
})); | |
app.post('/post', function (req, res) { | |
console.log(req.body); | |
res = res.status(200); | |
if (req.get('Content-Type')) { | |
console.log("Content-Type: " + req.get('Content-Type')); | |
res = res.type(req.get('Content-Type')); | |
} | |
res.send(req.body); | |
}); | |
http.createServer(app).listen(7000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment