Skip to content

New Server.listen(options[, callback]) method is too picky about port being a js number #1111

@brycebaril

Description

@brycebaril

Really like this new new listen function, but I've found it's pickier than the others about port being a js number vs a string number, and the error is unclear (uses poor stringification of the object):

// Old .listen(port[, host][, callback])
http.createServer(function (req, res) {
  res.end("\n")
}).listen("8005")

Works fine, converting "8005" to 8005.

While:

// New .listen(options[, callback])
http.createServer(function (req, res) {
  res.end("\n")
}).listen({port: "8005"})

Throws:

Error: Invalid listen argument: [object Object]
    at Server.listen (net.js:1278:15)
    at repl:1:56
    at REPLServer.defaultEval (repl.js:116:27)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.<anonymous> (repl.js:269:12)
    at emitOne (events.js:77:13)
    at REPLServer.emit (events.js:166:7)
    at REPLServer.Interface._onLine (readline.js:195:10)
    at REPLServer.Interface._line (readline.js:534:8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions