Home > Software engineering >  SvelteKit change port to different one
SvelteKit change port to different one

Time:10-13

I want to change port in production build of node-adapter. I use port 3000 internally for different service, so I need to change Svelte app to have port 3001.

My Dockerfile:

# Container setup ---------
FROM node:16-alpine as build

RUN mkdir /appbuild
COPY . /appbuild
WORKDIR /appbuild

# clean install all dependencies
RUN npm ci
# remove potential security issues
RUN npm audit fix
RUN npm run build

# Container setup ---------
FROM node:16-alpine
WORKDIR /app
# copy dependency list
COPY --from=build /appbuild/package*.json ./

# clean install dependencies, no devDependencies, no prepare script
RUN npm ci --production --ignore-scripts
# remove potential security issues
RUN npm audit fix
# copy built SvelteKit app to /app
COPY --from=build /appbuild/build ./
CMD ["node", "./index.js"]

I found that if I start app like PORT=3001 node build from root (after calling npm run build) it works, but for dockerfile, CMD must be provided and PORT cannot be passed. How to change default port to another one?

CodePudding user response:

Have you tried using ENV?

ENV PORT=3001
CMD ["node", "./index.js"]
  • Related