Skip to content

Instantly share code, notes, and snippets.

@sempostma
Forked from mmattozzi/package.json
Created January 4, 2020 11:05
Show Gist options
  • Save sempostma/b857681ec535d998511d42bcf63c0139 to your computer and use it in GitHub Desktop.
Save sempostma/b857681ec535d998511d42bcf63c0139 to your computer and use it in GitHub Desktop.
HTTP echo server using node.js and express
{
"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"
}
}
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