Skip to content

Instantly share code, notes, and snippets.

@numb86
Created October 4, 2017 06:23
Show Gist options
  • Save numb86/e35fffc4528d89c3eb1b1d788cf24fc0 to your computer and use it in GitHub Desktop.
Save numb86/e35fffc4528d89c3eb1b1d788cf24fc0 to your computer and use it in GitHub Desktop.
ローカルサーバーを立ててそこにリクエストするプログラム。
const http = require('http');
const req = require('request-promise');
const PORT_NUMBER = 8881;
const server = http.createServer();
server.on('request', (req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World !2!');
res.end();
server.close();
req.connection.end();
req.connection.destroy();
});
server.listen(PORT_NUMBER);
req({
method: 'GET',
url: `http://localhost:${PORT_NUMBER}`,
resolveWithFullResponse: true,
})
.then(res => console.log(res.headers));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment