1

If my Nexs.js app is started with

yarn dev

Where package.json defines it as

{
   "scripts": {
     "dev": "next dev -p 4000"
   }
}

How I get this 4000 value from the -p switch?

Because process.env.PORT is not set this way.

const getBaseUrl = () => {
  if (typeof window !== 'undefined') return '';  // browser use relative path

  // How to replace the ???? with the value of -p, defaulting to 3000 if not set

  return 'http://localhost:????';  // dev SSR should use localhost
}
Yanick Rochon
  • 51,409
  • 25
  • 133
  • 214

0 Answers0