Project using too much memory for what it is
blendibrahimi1
FREEOP

2 years ago

React frontend using 500mb of memory at all times

Closed

42 Replies

blendibrahimi1
FREEOP

2 years ago

26a337a7-989f-4742-8443-35c4e61b90f2


blendibrahimi1
FREEOP

2 years ago

1337182950156144671


2 years ago

yeah this is a dev server


2 years ago

copy the nixpacks.toml and caddyfile from this repo into your repo


how does one know if they are using a dev server?


blendibrahimi1
FREEOP

2 years ago

i used docker for this project


blendibrahimi1
FREEOP

2 years ago

that's what i was wondering as well


2 years ago

for this, i looked at the start command - react-scripts start

and that starts a dev server, thus, you are running a development server


ohhh


its not a railway thing


2 years ago

nope


makes much more sense


2 years ago

in this case, kalon is telling railway to run the dev server since its what their start script is set to


blendibrahimi1
FREEOP

2 years ago

makes sense yeah


blendibrahimi1
FREEOP

2 years ago

do i still need the nixpacks file even though i'm using docker?


blendibrahimi1
FREEOP

2 years ago

ahhh


blendibrahimi1
FREEOP

2 years ago

i'm dumb


2 years ago

you mean you are using a dockerfile?


2 years ago

yes you are, send me it please


blendibrahimi1
FREEOP

2 years ago

yes i'm dumb or yes i'm using dockerfile lol


blendibrahimi1
FREEOP

2 years ago

or both


blendibrahimi1
FREEOP

2 years ago

CMD ["npx", "serve", "-s", "build", "-l", "3000"]


2 years ago

lmao sorry, yes you are using a dockerfile


blendibrahimi1
FREEOP

2 years ago

this is what i got in my dockerfile


blendibrahimi1
FREEOP

2 years ago

that's the problem


2 years ago

would still use like 60mb


blendibrahimi1
FREEOP

2 years ago

FROM node:20

# Set the working directory
WORKDIR /app

# Copy the package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy the project files
COPY . .

# Build the app
RUN npm run build

# Expose the port the app runs on
EXPOSE 5000

# Start the app using a simple Node server with a fallback
CMD ["npx", "serve", "-s", "build", "-l", "3000"]```


blendibrahimi1
FREEOP

2 years ago

oh


2 years ago

enclose in code block please


blendibrahimi1
FREEOP

2 years ago

how?


2 years ago

triple backticks


blendibrahimi1
FREEOP

2 years ago

yeah mb


2 years ago

one sec


2 years ago

try this -

# Use an official Node.js runtime as a parent image
FROM node:20 AS builder

# Set the working directory
WORKDIR /app

# Copy the package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy the project files
COPY . ./

# Build the app
RUN npm run build

# Use the latest Caddy image
FROM caddy:latest

# Set the working directory
WORKDIR /app

# Copy the Caddyfile
COPY Caddyfile ./Caddyfile

# Format the Caddyfile
RUN caddy fmt Caddyfile --overwrite

# Copy the build files
COPY --from=builder /app/build ./build

# Start the app using Caddy
CMD ["caddy", "run", "--config", "Caddyfile", "--adapter", "caddyfile"]

2 years ago

you wont need the nixpacks.toml file, but you will need the caddyfile


blendibrahimi1
FREEOP

2 years ago

alright, Imma push the changes


blendibrahimi1
FREEOP

2 years ago

it's active now, i'll just wait and see if the memory usage goes down


blendibrahimi1
FREEOP

2 years ago

what's funny is that the other react project is in the same place here but uses a different dockerfile

FROM node:20

# Set the working directory
WORKDIR /app

# Copy the package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy the project files
COPY . .

# Build the TypeScript code
RUN npm run build

# Expose the port the app runs on
EXPOSE 3000

# Start the app
CMD ["npm", "start"]

blendibrahimi1
FREEOP

2 years ago

memory usage went down to 15mb


blendibrahimi1
FREEOP

2 years ago

🎉


blendibrahimi1
FREEOP

2 years ago

thanks, Brody o/


2 years ago

awsome!


Welcome!

Sign in to your Railway account to join the conversation.

Loading...