Skip to content

Instantly share code, notes, and snippets.

@mmattozzi
Created May 9, 2017 00:28
Show Gist options
  • Save mmattozzi/3a8abfa9de7c61f3e87d906b20063fc4 to your computer and use it in GitHub Desktop.
Save mmattozzi/3a8abfa9de7c61f3e87d906b20063fc4 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": {
"express": "^4.15.2"
}
}
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);
@judavi
Copy link

judavi commented Sep 5, 2019

Thanks for sharing! it works for me to help to identify an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment