Create Strapi-App launches with port 3000 and not 1337

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

I’m on a Mac running node v14.7.0. When running a new install of strapi following https://strapi.io/documentation/3.0.0-beta.x/installation/cli.html, it launched on port 3000 despite server.js saying 1337, the standard port used by Strapi. Changing server.js also doesn’t change the port. I’m assuming it’s something to do with my settings outside of Strapi. Is there any other place that could be overriding the port settings for strapi?

Why are you installing a beta version? Please check the latest version:
https://strapi.io/documentation/v3.x/installation/cli.html

You can also create the latest version project by adding the @latest suffix:
npx create-strapi-app@latest my-project --quickstart

I’m assuming you are running the app with --watch-admin flag?

As port 3000 is used for Admin development.

Thanks for the reply, while the url is for the beta, the directions look to be the same. I think this installs the most recent stable version.

Strapi is created using

yarn create strapi-app my-project --quickstart

When it launches, using ‘strapi dev’ the admin starts on port 3000

"One more thing…
Create your first administrator :computer: by going to the administration panel at:

┌─────────────────────────────┐
http://localhost:3000/admin
└─────────────────────────────┘

"
This is the contents of my /config/server.js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET', '4ea4d50da558033976b65e62901ae9cf'),
    },
  },
});

I’m running initially with

yarn create strapi-app my-project --quickstart

and then with “strapi dev”. Do you think there’s any chance there could be other settings in my environment overriding strapi’s default port setting?

I’m assuming you are using a Global installed Strapi, which is a different version from your local project. Because you can’t run an app with strapi dev, only with yarn strapi dev or npm run strapi dev.

Can you check the local version?
yarn strapi version
and the global installed one
strapi version

one update, when I run printenv in terminal, I have PORT=3000 set. I’m just confused as to how this could override the strapi settings.

Well, in that case for sure you have something that overwrites the strapis envs. Can you create the .env file with:

HOST=127.0.0.1
PORT=1337

I’ve done this and it still loads on port 3000. Is there a command I need to use to force the load of the local .env? Otherwise, I guess my overall environment settings are overriding.

Personally, I would recommend investigating what exactly is overwriting your envs in your system.
But if you don’t have time right now to investigate that, just modify the port property in /config/server.js:

port: 1337,

Or, create another env in .env:

HOST_PORT=1337

/config/server.js:

port: env.int('HOST_PORT', 1337),

Thank you for your help. These are good suggestions and I’ve tried them. I think somehow the settings in my zsh env variables are overriding things. I’ll hunt down how I can unset the port in my profile environment and see if it works.

Running

PORT=1337 strapi dev

does override, which further hints at an environment issue in my terminal profile.

Thanks again

We no longer recommend install the strapi package globally and instead suggest you use the built-in script within the package.json instead. So something like PORT=1337 yarn develop or PORT=1337 npm run develop. With global installed strapi you could have multiple problems in the future.

For posterity, I found the problem. I had “PORT = 3000” set in my .zshrc profile, which must have overridden the Strapi environment settings. I commented it out with a “#” , and then loaded a new terminal instance and checked that “PORT” wasn’t set using the “env” command.

I then ran “yarn strapi dev” in the strapi folder and it worked as expected, with the admin panel opening at “localhost:1337/admin”.