Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vitkarpov
Last active November 10, 2017 19:36
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 vitkarpov/bc5df44b78ba38896ae2f434659685f3 to your computer and use it in GitHub Desktop.
Save vitkarpov/bc5df44b78ba38896ae2f434659685f3 to your computer and use it in GitHub Desktop.
Example of http/2 landed in Node.js 9 without --expose-http2 flag
const http2 = require('http2');
const fs = require('fs');
const server = http2.createSecureServer({
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
});
server.on('error', (err) => console.error(err));
server.on('socketError', (err) => console.error(err));
server.on('stream', (stream, headers) => {
// stream is a Duplex
stream.respond({
'content-type': 'text/html',
':status': 200
});
stream.end('<h1>Hello World</h1>');
});
server.listen(8443);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment