You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Docs on http.Server.listen() need clarifications on accepted args #16300
Since the net module 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:
I could be misunderstanding but doesn't the http module already document this as such in server.listen([port][, hostname][, backlog][, callback])? Meaning any of these arguments can be safely omitted.
@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 literal undefined in place of the omitted argument(s).
I'll bring it back to the Flow team for discussion.
@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 numberserver.listen(8080);// This is interpreted as a port numberserver.listen(8080,functioncallback(){});
which consider the first Number as port, while the notation server.listen([port][, hostname][, backlog][, callback]) suggests that you could pass a backlog but no port.
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.
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 match server.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.
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.
Hi, @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...
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!
Activity
apapirovski commentedon Oct 18, 2017
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.mscdex commentedon 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.claudiopro commentedon Oct 19, 2017
@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.
joyeecheung commentedon Oct 19, 2017
Closing because the documentation is clear enough.
claudiopro commentedon Oct 19, 2017
@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):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 😄
joyeecheung commentedon Oct 19, 2017
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.)I can't really see how the second one can be matched either, for the same reason above.
joyeecheung commentedon Oct 19, 2017
@claudiopro OK I think there is another way to make it clearer, although that requires a lot of brackets...
[PR] Adds tests for Node http(s) modules, improves server.listen() defs
apapirovski commentedon 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.
BeniCheni commentedon Apr 27, 2018
Hi, @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:
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.
apapirovski commentedon Apr 27, 2018
@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". 👍
BeniCheni commentedon Apr 27, 2018
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!