Skip to content

Instantly share code, notes, and snippets.

@KenanBek
Last active November 4, 2020 22:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save KenanBek/c20d809f5283e3d56e181596a3a1a7e5 to your computer and use it in GitHub Desktop.
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
let body = {
"message": "Hello, world!",
"items": [
"str1",
"str2",
"str3"
]
};
const { headers, method, query, url } = req;
const responseBody = { headers, method, query, url, body };
res.write(JSON.stringify(responseBody));
res.end();
}).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment