Repository navigation
Docs on http.Server.listen() need clarifications on accepted args #16300
Description
Activity
I could be misunderstanding but doesn't the
httpmodule already document this as such inserver.listen([port][, hostname][, backlog][, callback])? Meaning any of these arguments can be safely omitted.Reacted by Claudio Procida and Benjamin Chen- addedhttpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.questionIssues asking questions about Node.js.Issues asking questions about Node.js.
on Oct 18, 2017 @apapirovski is right, any arguments inside brackets in docs are indicating optional parameters and
server.listen()already shows that, so I don't think anything needs to be changed on our end. It seems like a bug/issue with Flow.Reacted by Claudio Procida, Benjamin Chen and Singing Dinosaur@mscdex @apapirovski thanks for clearing my misunderstanding, effectively the behavior of Flow is inconsistent with what
server.listen()actually accepts, forcing the implementor to pass literalundefinedin place of the omitted argument(s).I'll bring it back to the Flow team for discussion.
Closing because the documentation is clear enough.
Reacted by Karl Morrison, J Tan and TFarleyMC@joyeecheung I'd ask you to leave this open as I believe there are still some inconsistencies.
The docs don't specify what is the expected behavior when encountering the signature with one argument
server.listen(Number), or with two arguments,server.listen(Number, Function):// This is interpreted as a port number server.listen(8080); // This is interpreted as a port number server.listen(8080, function callback() {});
which consider the first
Numberasport, while the notationserver.listen([port][, hostname][, backlog][, callback])suggests that you could pass abacklogbut noport.Additionally, the signature
server.listen(String, Function)can match bothserver.listen(path[, callback])andserver.listen([port][, hostname][, backlog][, callback])with onlyhostnameandcallbackset.I would like to clarify the expected behavior 😄
while the notation server.listen([port][, hostname][, backlog][, callback]) suggests that you could pass a backlog but no port.
I would interprete this as "if there is any argument, and the first one is a number ,then the first one is a port" though, I am not sure if this optional argument syntax has any formal standard, but to me the previous arguments can't be optional like that (
server.listen(backlog[, callback])does not matchserver.listen([port][, hostname][, backlog][, callback])because the[,part is there for a reason.)Additionally, the signature server.listen(String, Function) can match both server.listen(path[, callback]) and server.listen([port][, hostname][, backlog][, callback]) with only hostname and callback set.
I can't really see how the second one can be matched either, for the same reason above.
@claudiopro OK I think there is another way to make it clearer, although that requires a lot of brackets...
server.listen([[[port[, hostname[, backlog]]][, callback])Reacted by Benjamin Chen- added a commit that references this issue
on Oct 19, 2017 - addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.Issues that need assistance from volunteers or PRs that need help to proceed.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.and removedquestionIssues asking questions about Node.js.Issues asking questions about Node.js.
on Apr 13, 2018 If someone wants to, this could be updated based on the latest feedback from @joyeecheung or instead have a little paragraph that outlines the possible combinations or something. Either way, it's probably a good idea to update with something that's more accurate.
Reacted by Benjamin ChenHi, @apapirovski. After reviewing the previous comments of this "good first issue" issue, I'm happy to pick up this one and give it a "try" on your reference to the latest feedback from @ joyeecheung with suggestion in your last comment:
@ claudiopro OK I think there is another way to make it clearer, although that requires a lot of brackets...
server.listen([[[port[, hostname[, backlog]]][, callback])Saw your last comment from 14 days ago. So just want to confirm with you again, before I get the local stuff started.
I can at least try to start with the proposed signature, learn the proposed parameters with the brackets' syntax, and use my best judgement to write a draft of possible combinations of the signature's parameters, to at least get the draft & PR started.
@BeniCheni This has actually been addressed by the PR above linked above your comment. Thanks for your interest though! Hope to see you around on another "good first issue". 👍
Thanks, @apapirovski. Ah missed the referred PR above my comment. My Bad. 🤗 Will poke around on there “good first time” or “help wanted” labeled open issues. Have a great day!
This is in relation to facebook/flow#1684
While Flow typing a module that uses
http.Server.listen(), I received an error for the idiomatic form widely used in Node projects:Flow declares the types of
http.Server.listen()like this:which adheres to the documentation of the
httpmodule.Since the
netmodule normalizes the arguments and Node itself uses the shorthand forms in the docs on the same page (Event: 'connect', Event: 'upgrade'), I suggest to amend the documentation explaining the shorthand forms are both supported:Thoughts?