← Back
caprover deploy jounal node typescript

Deploy typescript node app with caprover

We're going to deploy a Nodejs backend with a React frontend. The project has the following structure:

api/ # node backend
client/ # react app
package.json # shared scripts

API #

Our API is written in typescript, so it needs transpilation. It's better to transpile in the development machine so we don't waste server resources, or event worst, get out of them: transpilation could be a memory and CPU intensive operation.

api/package.json:

{}

captain-definition #

api/captain-definition:

{
  "schemaVersion": 2,
  "dockerfilePath": "./Dockerfile"
}

Dockerfile #

FROM node:14

# Create app directory
RUN mkdir /app
WORKDIR /app

COPY package*.json ./

RUN npm install --production
COPY . .

EXPOSE 3033
CMD [ "node", "dist/src/server.js" ]

Create an application #

Deploy scripts #

api/package.json:

{
"deploy": "npm run deploy:build && npm run deploy:upload",
"deploy:upload": "npx caprover deploy -t ./deploy.tar -a api -n <server-name>",
"deploy:build": "tar -cvf ./deploy.tar --exclude='*.map' ./captain-definition ./package.json ./Dockerfile ./dist/*"
}

🖖