How do I set the server environment to a certain port?
For instance,
const app = require('express')()
const isProd = (process.env.NODE_ENV === 'production')
const port = process.env.PORT || 3000
I will always get false for isProd and 3000 for port
I don't see the usefulness of these two lines and I can just set them below manually:
app.get('/', function (req, res) {
const data = {message: 'Hello World!'}
return res.status(200).json(data);
})
app.listen(3000, function () {
console.log('listening on port 3030!')
})
Do I need some config file in my root?
Any ideas?
I am using Linux/ Ubuntu/ Kubuntu.
Try running your server using below command
set NODE_ENV=production && set PORT=7000 && node server.js
Or for Linux
NODE_ENV=production PORT=7000 node server.js
This will set environment and port for your Node server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With