Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Set the Server Port in Express Using Environment Variables

    Joel LordJoel Lord

    In this lesson we learn how to use environment variables to set the port of an express.

    expressExpress
    ^4.0.0
    nodeNode.js
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss