Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support port numbers as strings (maybe?) #285

Closed
fabiospampinato opened this issue Jul 7, 2021 · 3 comments
Closed

Support port numbers as strings (maybe?) #285

fabiospampinato opened this issue Jul 7, 2021 · 3 comments
Labels
wontfix This will not be worked on

Comments

@fabiospampinato
Copy link

fabiospampinato commented Jul 7, 2021

Is your feature request related to a problem? Please describe.

I'd like to write the cleanest code possible, and I think it's pretty common to want to write something like this:

app.listen ( process.env.APP_PORT );

The thing is that process.env.* variables are always strings, so I need to wrap that in Number:

app.listen ( Number ( process.env.APP_PORT ) );

Describe the solution you'd like

Maybe app.listen should accept a string for a port too just for this use case? Like it obviously should be a number ideally, but maybe accepting strings for making this cleaner and more express-compatible is worth it?

Describe alternatives you've considered

Wrapping those env variables in Number.

@fabiospampinato fabiospampinato added the enhancement New feature or request label Jul 7, 2021
@fabiospampinato
Copy link
Author

It seems that a port as a string works just the same, in some sense the types are kind of wrong then 🤔 I think it'd like to see this minor thing changed.

@talentlessguy
Copy link
Member

imo it's not quite safe to allow ports to be passed as strings because someone can do this:

app.listen('bruh')

which is not good

proper way to load port from env is to do this: app.listen(parseInt(process.env.PORT, 10))

@talentlessguy talentlessguy added wontfix This will not be worked on and removed enhancement New feature or request labels Jul 7, 2021
@fabiospampinato
Copy link
Author

fabiospampinato commented Jul 7, 2021

That's too noisy IMO, I think it's ok to throw if the thing passed to once piped to parseInt doesn't become a number > 0.

But I'm ok with this being a number too, the resulting code is just a bit less clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants