Welcome to the Linux Foundation Forum!

Avoid Hard coding PORT


I just want to make sure I understand what an assignment asks when it tells me I can't hard code the PORT variable. Do I assume there's going to be a .env holding the PORT variable that the server calls upon and write the listen function as so:

app.listen(process.env.PORT || 3000)

Or is there something else I have to do like make the .env myself? Also does this apply to implementing a Data Aggregating Service that need certain ports to connect to?

Best Answer

  • xdxmxc
    xdxmxc Posts: 148
    Answer ✓

    there's to .env involved, but yes the PORT environmental variable is externally set by validation software - as long as your passing process.env.PORT you're good


Upcoming Training