Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Re: Shopify CLI 3 Question

Solved

How to force a specific port in CLI v3 project?

tomadelaney
Shopify Partner
18 2 2

I am in the process of converting an old project from CLIv2 to the new CLIv3 structure.
My issue: CLI v3 seems to always randomly update the process.env.PORT to a 5xxxx number,

and then configures the ngrok tunnel through this port.  

 

I've tried forcing the port number to 3000 by changing the dev script
from:

"dev": "NODE_ENV=development nodemon --exec babel-node server/index.js --watch server/" 

to:

"dev": "cross-env PORT=3000 nodemon --exec babel-node server/index.js --watch server/",

... but in this case, the tunnel is created at 3000, but the CLI tries to open a second ngrok tunnel, resulting in a 'you are only allowed one tunnel" error.

 

My question: how do I configure a my CLI v3 project to force a specific port (3000) to be passed in as process.env.PORT within the CLI 'shopify app dev' script?  .
I've had no luck passing variables in through a .env file. 
If anybody can point me to a working example, I would greatly appreciate it!

Accepted Solution (1)

StoreWatchers
Trailblazer
205 30 37

This is an accepted solution.

Hello @tomadelaney,

 

This is AJ from StoreWatchers. 

 

You can set port in shopify.web.toml configuration file. Please find more detail on Shopify official page https://shopify.dev/docs/apps/tools/cli/migrate#web-component-conventions

 

Thanks

StoreWatchers - Automate testing for your Shopify store in seconds


If you find my reply helpful, please hit Like and Mark as Solution
Visit us: App Store | Website | FAQs

View solution in original post

Replies 2 (2)

StoreWatchers
Trailblazer
205 30 37

This is an accepted solution.

Hello @tomadelaney,

 

This is AJ from StoreWatchers. 

 

You can set port in shopify.web.toml configuration file. Please find more detail on Shopify official page https://shopify.dev/docs/apps/tools/cli/migrate#web-component-conventions

 

Thanks

StoreWatchers - Automate testing for your Shopify store in seconds


If you find my reply helpful, please hit Like and Mark as Solution
Visit us: App Store | Website | FAQs
tomadelaney
Shopify Partner
18 2 2
AJ,
 
Thank you for your reply.
 
I’ve tried to work through the CLI migration guide in the past, with many permutations of PORT, SERVER_PORT and BACKEND_PORT in the shopify.web.toml files.  The CLI seems to still randomly insert its own port.
 
I will work through the migration guide again, and document my solution in this thread if I succeed.  
 
Thanks again for your reply.
Tom