question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work with Express.js

See original GitHub issue

I wrote simple Express app and got an error.

var fs = require('fs');
var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('hello!')
})

var options = {
  key: fs.readFileSync('./ssl/key.pem'),
  cert: fs.readFileSync('./ssl/cert.pem')
};

require('http2').createServer(options, app).listen(8080);
// require('https').createServer(options, app).listen(8080);// https module works well
_stream_readable.js:505
    dest.end();
         ^
TypeError: undefined is not a function
    at Stream.onend (_stream_readable.js:505:10)
    at Stream.g (events.js:199:16)
    at Stream.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)

Is that a node-http2’s matter or Node’s one? It is hard to debug for me…

Node: v0.12.0 node-http2: v3.2.0 express: v4.11.2

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:43 (10 by maintainers)

github_iconTop GitHub Comments

13reactions
JakeChampioncommented, May 11, 2016

@gajus could you put that big log code block into a gist at all? It is making the page very large.

13reactions
gajuscommented, Jul 7, 2016

Using:

"express": "^5.0.0-alpha.2",
"http2": "^3.3.4",
const http2 = require('http2');
const express = require('express');
const yargs = require('yargs');
const path = require('path');
const fs = require('fs');

const argv = yargs
      .help()
    .strict()
    .options({
        port: {
            default: 8000,
            demand: true,
            type: 'number'
        }
    })
    .argv;

process.on('unhandledRejection', (reason, promise) => {
    /* eslint-disable no-console */
    console.log('Unhandled RejectionPromise');
    console.log('promise', promise);
    console.log('reason', reason);
    console.log('reason.stack', reason.stack);
    /* eslint-enable */
});

const app = express();


app.get('/', (req, res) => {
    res.json({foo: 'test'});
});

/* eslint-disable no-console, no-unused-vars */
app.use((err, req, res, next) => {
    console.error(err.stack);
    /* eslint-enable */

    res
        .status(500)
        .send('Internal Server Error');
});

http2
    .createServer({
        log: require('bunyan').createLogger({name: 'myapp'}),
        key: fs.readFileSync(path.resolve(__dirname, './localhost.key')),
        cert: fs.readFileSync(path.resolve(__dirname, './localhost.crt'))
    }, app)
    .listen(argv.port, (err) => {
        if (err) {
            throw new Error(err);
        }

        /* eslint-disable no-console */
        console.log('Listening on port: ' + argv.port + '.');
        /* eslint-enable no-console */
    });

Does not work.

The complete log output: https://gist.github.com/gajus/843fd2d682f946680af161b7054b01f2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express Node.js doesn't work - Stack Overflow
So I have no idea of which port express is running on or whether or not it is running at all.
Read more >
Express/Node introduction - Learn web development | MDN
js ) is an open-source, cross-platform runtime environment that allows developers to create all kinds of server-side tools and applications in ...
Read more >
Top 10 Most Common Node.js Developer Mistakes - Toptal
Mistake #4: Expecting Callbacks to Run Synchronously. Asynchronous programming with callbacks may not be something unique to JavaScript and Node.js, but they ...
Read more >
Node.js Error: Cannot GET/ from running the url on the web ...
Problem Statement: On running a Node. · Example: Let's create a simple Node. · Step 1: Initializes NPM: · Step 2: Install Dependencies:...
Read more >
app.use not working · Issue #4390 · expressjs/express - GitHub
Our first request would be for you to create a very small program that demonstrates the issue and the http requests you are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found