Sveltekit with adapter-node

Can annybody help me how to deploy a sveltekit app with adapter-node?
I used the “NodeJS SSR” settings at adding the app. I also installed dotenv.
The app is building, but I get an 502 Bad gateway error calling it in the browser.
pm2 list shows status errored.

If I start the app in the current-folder with node -r dotenv/config build, the app starts at port 3000. Chnging the port in the nginx config to 3000, the app is working. So I have to execute the start command and change the port and configure pm2 propably. How?

Hello @romanw,

We’ll look into the issue and get back to you.

@romanw for port 3000, you can first set that when creating a new site. If changing afterwards, you’d do that in the site’s NGINX config -

location / {
      ...
      proxy_pass              http://localhost:3000;
     ... 
  }

And also in the deployment workflow > PM2 section -

env: {
    "PORT": 3000,
     ....  
  }

If you are getting a 502 error, take a look in the Server > Services section and click the heartbeat for Node JS. View the PM2 logs that will show and see if PM2 is complaining about anything. Often times, it may be something like it can’t find a start file, can’t connect to a db, started on a port already in use, is missing an env variable, etc.

It works with following pm2 config:

  name: "example.com",
  script: "./build/index.js",
  args: "",
  log_type: "json",
  cwd: "/home/cleavr/example.com/artifact",
  // Note: We detected that this web app is running on a server with multiple CPUs and hence we are
  // setting *instances* to "max" and *exec_mode* to "cluster_mode" for better performance.

  instances : "max", // change the value to "1" if your server has only 1 CPU
  exec_mode : "cluster_mode", // remove this line if your server has only 1 CPU
  env: {
    "PORT": 3000,
    ENV_PATH: "./.env",
    "CI": 1,
    "NUXT_TELEMETRY_DISABLED": 1
  }
}

I set no artifact folder and changed the port in the nginx config to 3000.
Thank you!

Edit: You can change the port 3000 to any other (leave the one cleavr sets on site creation). It has to be the same in pm2 and nginx, of course.

1 Like