How do I change port using dotenv and skeltekit node-adapter in production?

Viewed 345

I have this in my svelte.config.js file but it appears to be ignored in production (it works fine with npm run dev)

import dotenv from 'dotenv-flow';
import adapter from '@sveltejs/adapter-node';


dotenv.config();

...
        adapter: adapter({
            out: './build',
            precompress: true
        }),
        vite: {
            ...
            server: {
                port: process.env.PORT || 3000
            }
        }

I do not see dotenv anywhere in the build/ directory which means its ignoring .env.local

There are other environment variables my app needs as well its not just port.

My production app is started with systemd using cd build && node index.js

1 Answers

Because I use systemd I have a script in ./bin/start.sh

I am now passing PORT for now but the sveltekit build should handle this in my opinion.

start.sh:

. .env
. .env.local

PORT=${PORT} node build/index.js
Related