Port 1337 is already used on VPS

System Information
  • Strapi Version: 4.7.1
  • Operating System: Windows 11
  • Database:
  • Node Version: v14.20.1
  • NPM Version: v6.14.17
  • Yarn Version:

Hi, I can’t connect with my strapi on private paid VPS. Below are my steps:

my package.json file:

{
  "name": "my-strapi-project",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "develop": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },
  "devDependencies": {},
  "dependencies": {
    "@strapi/strapi": "4.7.1",
    "@strapi/plugin-users-permissions": "4.7.1",
    "@strapi/plugin-i18n": "4.7.1",
    "better-sqlite3": "8.0.1"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "c545328d-295a-49b6-8d97-81955caa43f0"
  },
  "engines": {
    "node": ">=14.19.1 <=18.x.x",
    "npm": ">=6.0.0"
  },
  "license": "MIT"
}
  1. Created and built strapi files on PC (it works on localhost).
  2. My config/server.js file contants:
module.exports = ({ env }) => ({
  host: env("HOST", "0.0.0.0"),
  port: env.int("PORT", 1337),
  url: env("URL", "http://codepage.pl"),
  app: {
    keys: env.array("APP_KEYS"),
  },
  webhooks: {
    populateRelations: env.bool("WEBHOOKS_POPULATE_RELATIONS", false),
  },
});

codepage.pl is my domain

  1. Create nodeJS on VPS and transfer strapi files by FTP
  2. Set “npm config set scripts-prepend-node-path true” (had some issues before without it)
  3. Pass “npm i”
npm WARN deprecated mini-create-react-context@0.4.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm WARN deprecated mailcomposer@3.12.0: This project is unmaintained
npm WARN deprecated buildmail@3.10.0: This project is unmaintained
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated

> sharp@0.31.1 install /home/srv43578/nodevenv/nodejs/14/lib/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)

sharp: Using cached /home/srv43578/.npm/_libvips/libvips-8.13.2-linux-x64.tar.br
sharp: Integrity check passed for linux-x64

> better-sqlite3@8.0.1 install /home/srv43578/nodevenv/nodejs/14/lib/node_modules/better-sqlite3
> prebuild-install || node-gyp rebuild --release


> core-js-pure@3.29.1 postinstall /home/srv43578/nodevenv/nodejs/14/lib/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js:
> https://opencollective.com/core-js
> https://patreon.com/zloirock
> https://boosty.to/zloirock
> bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz

I highly recommend reading this: https://github.com/zloirock/core-js/blob/master/docs/2023-02-14-so-whats-next.md


> esbuild@0.16.17 postinstall /home/srv43578/nodevenv/nodejs/14/lib/node_modules/esbuild
> node install.js


> @strapi/strapi@4.7.1 postinstall /home/srv43578/nodevenv/nodejs/14/lib/node_modules/@strapi/strapi
> node lib/utils/success.js

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/android-arm@0.16.17 (node_modules/esbuild/node_modules/@esbuild/android-arm):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/android-arm@0.16.17: wanted {"os":"android","arch":"arm"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/android-arm64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/android-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/android-arm64@0.16.17: wanted {"os":"android","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/android-x64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/android-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/android-x64@0.16.17: wanted {"os":"android","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/darwin-arm64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/darwin-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/darwin-arm64@0.16.17: wanted {"os":"darwin","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/darwin-x64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/darwin-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/darwin-x64@0.16.17: wanted {"os":"darwin","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/freebsd-arm64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/freebsd-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/freebsd-arm64@0.16.17: wanted {"os":"freebsd","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/freebsd-x64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/freebsd-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/freebsd-x64@0.16.17: wanted {"os":"freebsd","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-arm@0.16.17 (node_modules/esbuild/node_modules/@esbuild/linux-arm):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-arm@0.16.17: wanted {"os":"linux","arch":"arm"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-arm64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/linux-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-arm64@0.16.17: wanted {"os":"linux","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-ia32@0.16.17 (node_modules/esbuild/node_modules/@esbuild/linux-ia32):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-ia32@0.16.17: wanted {"os":"linux","arch":"ia32"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-loong64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/linux-loong64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-loong64@0.16.17: wanted {"os":"linux","arch":"loong64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-mips64el@0.16.17 (node_modules/esbuild/node_modules/@esbuild/linux-mips64el):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-mips64el@0.16.17: wanted {"os":"linux","arch":"mips64el"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-ppc64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/linux-ppc64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-ppc64@0.16.17: wanted {"os":"linux","arch":"ppc64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-riscv64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/linux-riscv64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-riscv64@0.16.17: wanted {"os":"linux","arch":"riscv64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/linux-s390x@0.16.17 (node_modules/esbuild/node_modules/@esbuild/linux-s390x):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/linux-s390x@0.16.17: wanted {"os":"linux","arch":"s390x"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/netbsd-x64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/netbsd-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/netbsd-x64@0.16.17: wanted {"os":"netbsd","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/openbsd-x64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/openbsd-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/openbsd-x64@0.16.17: wanted {"os":"openbsd","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/sunos-x64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/sunos-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/sunos-x64@0.16.17: wanted {"os":"sunos","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/win32-arm64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/win32-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/win32-arm64@0.16.17: wanted {"os":"win32","arch":"arm64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/win32-ia32@0.16.17 (node_modules/esbuild/node_modules/@esbuild/win32-ia32):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/win32-ia32@0.16.17: wanted {"os":"win32","arch":"ia32"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @esbuild/win32-x64@0.16.17 (node_modules/esbuild/node_modules/@esbuild/win32-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @esbuild/win32-x64@0.16.17: wanted {"os":"win32","arch":"x64"} (current: {"os":"linux","arch":"x64"})

added 1460 packages from 2017 contributors and audited 1482 packages in 76.551s

126 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
  1. Copy server.js content from Deployment | Strapi Documentation
  2. Pass NODE_ENV=production npm run start

> my-strapi-project@0.1.0 build /home/srv43578/nodejs
> strapi build

Building your admin UI with development configuration...

✔ Webpack
  Compiled successfully in 17.82s

Admin UI built successfully
  1. Pass NODE_ENV=production npm run build
> my-strapi-project@0.1.0 start /home/srv43578/nodejs
> strapi start

[2023-03-14 18:27:42.871] debug: ⛔️ Server wasn't able to start properly.
[2023-03-14 18:27:42.873] error: The port 1337 is already used by another application.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-strapi-project@0.1.0 start: `strapi start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-strapi-project@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
  1. Lastly I tried to node server.js and the result is below:
  throw err;
  ^

Error: Cannot find module 'strapi'
Require stack:
- /home/srv43578/nodejs/server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/home/srv43578/nodejs/server.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/srv43578/nodejs/server.js' ]

Please, help me :slight_smile:

You can try an other port. if you switch in the env your port to an other one than that would maby fix it

I added inside my .env file:

HOST=0.0.0.0
PORT=1338

and it runs

> my-strapi-project@0.1.0 start /home/srv43578/cms
> strapi start

 Project information
┌────────────────────┬──────────────────────────────────────────────────┐
│ Time               │ Tue Mar 14 2023 19:09:16 GMT+0100 (czas środkow… │
│ Launched in        │ 779 ms                                           │
│ Environment        │ development                                      │
│ Process PID        │ 3216673                                          │
│ Version            │ 4.7.1 (node v14.20.1)                            │
│ Edition            │ Community                                        │
│ Database           │ sqlite                                           │
└────────────────────┴──────────────────────────────────────────────────┘

 Actions available

Welcome back!
To manage your project 🚀, go to the administration panel at:
http://codepage.pl/admin

To access the server ⚡️, go to:
http://codepage.pl

but when I try to enter my /admin page the result is 404 error.

While being inside my page console.log says

GET http://codepage.pl/api/restaurants?fields=name,description&populate=image 503 (Service Unavailable)
Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON

and still the result of command node server.js is:

[cms (14)] [srv43578@h23 cms]$ node server.js
internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'strapi'
Require stack:
- /home/srv43578/cms/server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/home/srv43578/cms/server.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/srv43578/cms/server.js' ]
}

I prevent building my strapi app inside my VPS and it worked.