
Nx is a next generation build system with first class monorepo support and powerful integrations.
In this guide you will create a new Nx workspace with a NestJS boilerplate API and build and deploy with Docker on Northflank.
npx create-nx-workspace --preset=nest
Questions:
- Workspace name (Becomes the parent folder name)
- Application name (Name of the first application in the Monorepo)
- Caching (Y/N) N
Wait for npx to create the project with on-demand npm package installs.
Install the Nx CLI
npm install nx -g
cd workspace-name
npm start
> nx serve
> nx run starter:serve
chunk (runtime: main) main.js (main) 2.86 KiB [entry] [rendered]
webpack compiled successfully (49e2d00594e067a3)
Debugger listening on ws://localhost:9229/fccec391-f2c0-4022-9ea3-ad6e510d0935
Debugger listening on ws://localhost:9229/fccec391-f2c0-4022-9ea3-ad6e510d0935
For help, see: https://nodejs.org/en/docs/inspector
[Nest] 11424 - 05/08/2022, 01:00:24 LOG [NestFactory] Starting Nest application...
[Nest] 11424 - 05/08/2022, 01:00:24 LOG [InstanceLoader] AppModule dependencies initialized +24ms
[Nest] 11424 - 05/08/2022, 01:00:24 LOG [RoutesResolver] AppController {/api}: +4ms
[Nest] 11424 - 05/08/2022, 01:00:24 LOG [RouterExplorer] Mapped {/api, GET} route +2ms
[Nest] 11424 - 05/08/2022, 01:00:24 LOG [NestApplication] Nest application successfully started +2ms
[Nest] 11424 - 05/08/2022, 01:00:24 LOG 🚀 Application is running on: http://localhost:3333/api
Create a Dockerfile at the root of the project. Your Nx workspace, shared libraries and apps will be built using the Dockerfile below:
Dockerfile
Replace nx-test
with the app you wish to deploy.
FROM node:lts-alpine as builder
WORKDIR /app
RUN npm install nx -g
COPY package.json .
COPY package-lock.json .
COPY nx.json .
RUN npm install
COPY . .
RUN npm run build
FROM node:lts-alpine as runtime
WORKDIR /app
COPY --from=builder /app/dist/apps/nx-test .
ENV PORT=3333
EXPOSE ${PORT}
COPY package.json .
COPY package-lock.json .
RUN npm install --omit=dev
CMD node ./main.js
Northflank allows you to deploy your code and databases within minutes. Sign up for a Northflank account and create a free project to get started.
- Multiple read and write replicas
- Observe & monitor with real-time metrics & logs
- Low latency and high performance
- Backup, restore and fork databases
- Private and optional public load balancing as well as Northflank local proxy