In this lesson we learn how to use environment variables to set the port of an express.
Instructor: [00:00] We'll change the port that this server is using. We'll use process.env for environment, and we'll create a new variable called port. If the port environment variable is not defined, we'll still use 8888 as a default.
[00:15] If you run this server, we see that the server is running on port 8888. If we do a next port and we set the port into our operating system to say 3000 and we run this server again, we can see that the server is now running on port 3000.
[00:34] If we open our browser, we go to localhost:8888, it can't be reached. If we go to 3000, we're getting a 404 in this case. If we go to 3000/status, we are getting the server time.
[00:48] That's how you set the port inside an environment variable.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!