question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect output when using environment PORT

See original GitHub issue

🐛 bug report

When setting the port using the environment variable PORT; parcel incorrectly reports that the port could not be used.

🎛 Configuration (.babelrc, package.json, cli command)

Command line:

set PORT=3000
node --max-old-space-size=8192 node_modules/parcel-bundler/bin/cli.js serve -d build/serve --no-autoinstall --cache-dir build/serve_cache src/*.html

Server running at http://localhost:3000 - configured port 3000 could not be used.

🤔 Expected Behavior

Expects parcel to report:

Server running at http://localhost:3000

😯 Current Behavior

Parcel reports:

Server running at http://localhost:3000 - configured port 3000 could not be used.

💁 Possible Solution

In src/Server.js

 let addon =
        server.address().port !== port
          ? `- ${logger.chalk.yellow(
              `configured port ${port} could not be used.`
            )}`
          : '';

server.address().port is a number port could be a string or a number; when specifying an environment PORT on Windows, it seems that port is a string

Adding a Number.parseInt to the port seems to fix the problem:

 let addon =
        server.address().port !== Number.parse(port)
          ? `- ${logger.chalk.yellow(
              `configured port ${port} could not be used.`
            )}`
          : '';

🌍 Your Environment

Software Version(s)
Parcel 1.12.3
Operating System Windows 10

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

1reaction
callumgarecommented, Mar 10, 2020

@ppqn This was annoying me so I’ve submitted a pull request 😃

0reactions
JwanKhalafcommented, Oct 19, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why after setting value to environment variable PORT the ...
The output in the terminal is listening to port undefined . My OS is Windows. I tried solutions online, such as PORT=2000 node...
Read more >
env variables from .env file are not set in docker compose file
I was typing the command "docker-compose up -d" in the wrong directory.
Read more >
Working with Environment Variables in Node.js - Twilio
This code should output all environment variables that this Node.js ... Cloud hosts like Heroku or Azure, however, use the PORT variable to ......
Read more >
Using Environment Variables in Node.js for App Configuration ...
Learn why experienced Node.js developers use environment variables for app config and secrets, including how to manage default values and ...
Read more >
Cloud Foundry Environment Variables
Cloud Foundry allocates a port dynamically for each instance of the app, so code that obtains or uses the app port should refer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found