Skip to content

Instantly share code, notes, and snippets.

@harish2704
Last active November 8, 2023 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harish2704/fe6fba3a0377b4e4608a3be9e8086c26 to your computer and use it in GitHub Desktop.
Save harish2704/fe6fba3a0377b4e4608a3be9e8086c26 to your computer and use it in GitHub Desktop.
A dummy express server which will dump headers , url , method & body of the request

express-dummy-server

const express = require('express')
const app = express()
const port = process.env.PORT || 3002
app.use(express.text());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(function( req, res ){
const data = {
method: req.method,
headers : req.headers,
body: req.body,
url: req.path,
};
'method headers body originalUrl'.split(' ').forEach(function(key){
console.log(`==${key}==`);
var data = req[key];
console.log( data instanceof Object ? JSON.stringify( data, null, ' ') : data );
console.log('\n');
})
return res.sendStatus(200);
})
app.listen( port, '0.0.0.0', () => console.log(`Example app listening on port http://0.0.0.0:${port}!`))
{
"name": "express-dummy-server",
"packageManager": "yarn@3.2.3",
"dependencies": {
"express": "^4.18.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment