Created
July 6, 2021 09:57
-
-
Save imposibrus/1c1cb03ab3e7e71752f505e8b12a7aec to your computer and use it in GitHub Desktop.
Node.js servers one-liners
This file contains hidden or 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
require('http').createServer((req, res) => {console.log(req.headers);res.writeHead(200);res.end('Hello, World!');}).listen(3000, '0.0.0.0') |
This file contains hidden or 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
require('http2').createServer().on('stream', (s, h) => {console.log(h);s.respond({':status': 200});s.end('Hello, World!');}).listen(3000, '0.0.0.0') |
This file contains hidden or 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
require('net').createServer((c) => {console.log('client connected');c.on('end', () => {console.log('client disconnected');});c.write('Hello, World!\r\n');c.pipe(c);}).listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment