How to integrate http2 with ExpressJS using nodejs module http2?
expressjs
still does not officially support Node http2
But you can use node-spdy
. With this module, you can create HTTP2 / SPDY servers in node.js with natural http module interface and fallback to regular https (for browsers that support neither HTTP2 nor SPDY yet).
const port = 3000 const spdy = require('spdy') const express = require('express') const path = require('path') const fs = require('fs') const app = express() app.get('*', (req, res) => { res .status(200) .json({message: 'ok'}) }) const options = { key: fs.readFileSync(__dirname + '/server.key'), cert: fs.readFileSync(__dirname + '/server.crt') } console.log(options) spdy .createServer(options, app) .listen(port, (error) => { if (error) { console.error(error) return process.exit(1) } else { console.log('Listening on port: ' + port + '.') } })
For more datils on spdy
, visit here.
if you have an option for other frameworks you can use 'KOA' or 'HAPI' which have support for node http2
. This might be useful for you
Also, Read this Release 5.0#2237, It says that:
The goal of Express 5 is to be API tweaks & the removal of all codefrom the Express repository, moving into components in the pillarjsproject (https://github.com/pillarjs), providing at least basicsupport for promise-returning handlers and complete HTTP/2functionality. Express 5 would become a "view into pillarjs" and wouldbe an arrangement of these components.