Last active
November 8, 2023 11:09
-
-
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
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
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}!`)) |
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": "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