So the next time you set up

Connect Asia Data learn, and optimize business database management.
Post Reply
hasinam2206
Posts: 19
Joined: Sun Dec 22, 2024 3:49 am

So the next time you set up

Post by hasinam2206 »

JavaScript Copy the code console.log(process.env); This code should produce all the environment variables that this Node.js process can retrieve. To access a specific variable, do as for any property of an object: JavaScript Copy the code console.log('The value of PORT is:', process.env.PORT); You'll notice here that the value of PORTis not set on your computer.

However, cloud hosts like Heroku or Azure 11-digit phone number format philippines use the variable PORTto tell you what port your server should be listening on for routing to work properly.a web server, you can determine which port to listen on by first checking the PORTand then giving it a default value: JavaScript Copy the code const app = require('http').

Image

createServer((req, res) => res.send('Ahoy!')); const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server is listening on port ${PORT}`); }); The highlighted line will take the value of PORTif it is available or listen by default 3000as a fallback port. Try running the code by saving it to a file like and server.

jsthen run: JavaScript Copy the code node server.js The result should be a message saying " Server is listening on port 3000 ". Stop the server using the keys Ctrl+Cand restart it using the following command: JavaScript Copy the code PORT=9999 node server.js The message now says "Server is listening on port 9999". This means that the variable PORThas been temporarily placed in front of the node for this run by PORT=9999.
Post Reply