Node.js - Easy way to change port

So I run Node.js using Laragon and set NGINX in the front of server request so that the website is reachable from http://localhost/ instead of http://localhost:3000/. My question is, is there easy way to configure Development target to port 3000 and Production target to port 80?

Is there anything else I need to amend other than port: process.env.PORT || 80 in config.js ?

You can set the port in app/config/config.json otherwise upgrades to Wappler will overwrite your change in the js file.

{
   "port": 3005
}
2 Likes

As Ken already says, you should not edit the files in the lib folder. You can edit the config.json like Ken told or many hosts allow you to set environment variables, just set the environment variable PORT to 80.

Do you have complete example because simply adding this line doesn’t work in my environment and I get this error in Wappler console. [nodemon] app crashed - waiting for file changes before starting...

I wrote that code section on my phone which displayed curly quotes – I’ve changed it above to regular keyboard quotes. If you copied that code and pasted, it might be causing the problem. Make sure you only have regular quotes in your code.

Other than that, there isn’t much I can add…what you see above is a full example.

I need reference to do this in Wappler. I’ve read some tutorials on environment variables and found it quite complicated to apply. In my OP, I just need to change the port number and that’s it.

I’ve tried with and without quotes. Got the same error. Thanks anyway.

You get the error after changing the config.json? Then you probably generated some invalid json, post your json file here and we will check what is wrong.

{
“debug”: true,
“secret”: “wO3ikXSgfEntiin”
}
{
“port”: 80
}

Change it to:

{
  "debug": true,
  "secret": "wO3ikXSgfEntiin",
  "port": 80
}
3 Likes

Thanks for the correction. It works now. :santa: