Project using too much memory for what it is
blendibrahimi1
FREEOP

a year ago

React frontend using 500mb of memory at all times

42 Replies

blendibrahimi1
FREEOP

a year ago

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


blendibrahimi1
FREEOP

a year ago

1337182950156144600


a year ago

yeah this is a dev server


a year 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

a year ago

i used docker for this project


blendibrahimi1
FREEOP

a year ago

that's what i was wondering as well


a year 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


a year ago

nope


makes much more sense


a year ago

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


blendibrahimi1
FREEOP

a year ago

makes sense yeah


blendibrahimi1
FREEOP

a year ago

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


blendibrahimi1
FREEOP

a year ago

ahhh


blendibrahimi1
FREEOP

a year ago

i'm dumb


a year ago

you mean you are using a dockerfile?


a year ago

yes you are, send me it please


blendibrahimi1
FREEOP

a year ago

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


blendibrahimi1
FREEOP

a year ago

or both


blendibrahimi1
FREEOP

a year ago

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


a year ago

lmao sorry, yes you are using a dockerfile


blendibrahimi1
FREEOP

a year ago

this is what i got in my dockerfile


blendibrahimi1
FREEOP

a year ago

that's the problem


a year ago

would still use like 60mb


blendibrahimi1
FREEOP

a year ago

```# Use an official Node.js runtime as a parent image
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

a year ago

oh


a year ago

enclose in code block please


blendibrahimi1
FREEOP

a year ago

how?


a year ago

triple backticks


blendibrahimi1
FREEOP

a year ago

yeah mb


a year ago

one sec


a year 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"]

a year ago

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


blendibrahimi1
FREEOP

a year ago

alright, Imma push the changes


blendibrahimi1
FREEOP

a year ago

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


blendibrahimi1
FREEOP

a year ago

what's funny is that the other react project is in the same place here but uses a different dockerfile
```# Use an official Node.js runtime as a parent image
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

a year ago

memory usage went down to 15mb


blendibrahimi1
FREEOP

a year ago

🎉


blendibrahimi1
FREEOP

a year ago

thanks, Brody o/


a year ago

awsome!


Loading...