Hongbo Miao Hongbo Miao - 3 months ago 121
Node.js Question

TypeError: dest.end is not a function

I am trying to use HTTP/2. My express version is 5.0.0-alpha.2, http2 version is 3.3.4.

I suppose http2 should work well with express 5.

const http2 = require('http2');
// const http2 = require('spdy'); // using spdy package here, everything works perfect

const options = {
key: fs.readFileSync(path.join(__dirname, 'private', 'server.key')),
cert: fs.readFileSync(path.join(__dirname, 'private', 'server.crt'))
};

const server = http2
.createServer(options, app)
.listen(3000, err => {
if (err) throw new Error(err);

// I can see "Listening..." message, which means the server starts running well.
console.log('Listening...');
});


The server starts running well, but when I open client website, it gives me this error in the terminal:


_stream_readable.js:512
dest.end();
^

TypeError: dest.end is not a function
at Stream.onend (_stream_readable.js:512:10)
at Stream.g (events.js:286:16)
at emitNone (events.js:91:20)
at Stream.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)


Answer

It seems node-http2 has not been supported by Express yet. Please track this issue Support for module http on github.

In the meanwhile, you can stay with node-spdy.

const spdy = require('spdy');

const options = {
  key: fs.readFileSync(path.join(__dirname, 'private', 'server.key')),
  cert: fs.readFileSync(path.join(__dirname, 'private', 'server.crt'))
};

const server = spdy
  .createServer(options, app)
  .listen(3000, err => {
    if (err) throw new Error(err);
    console.log('Listening...');
  });