A full-stack nestjs starter project. Includes authorization, authentication, MongoDB, Redis queue support, Crons jobs, and end-to-end testing.
This is a monorepo boilerplate to quickly start nestjs projects, this start includes an api, client and shared libraries.
The repository is powered by Lerna and Yarn.
Lerna is responsible for bootstrapping, installing, symlinking all of the packages/apps together.
This repo includes multiple packages and applications for a hypothetical project called nest-starter
. Here’s a rundown of the components:
shared
: Shared utilities between server and client (TypeScript)core
: Shared utilities between serversclient
: Angular app (depends on shared
)api
: NestJS Api server (depends on shared
+ core
)landing
: A static landing pageYou should run a search and replace on the word nest-starter
and replace with your project name.
Each package can be referenced within other packages/app files by importing from @<name>/<folder>
(kind of like an npm scoped package).
import * as React from 'react';
import { Button } from '@nest-starter/shared';
class App extends React.Component<any> {
render() {
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">Welcome to React</h1>
</header>
<Button>Hello</Button>
<p className="App-intro">
To get started, edit <code>src/App.tsx</code> and save to reload.
</p>
</div>
);
}
}
export default App;
IMPORTANT: YOU DO NOT NEED TO CREATE/OWN THE NPM ORGANIZATION OF YOUR PROJECT NAME BECAUSE NOTHING IS EVER PUBLISHED TO NPM.
For more info, see the section on package versioning
Install lerna globally.
npm i -g lerna
git clone [email protected]:scopsy/nestjs-monorepo-starter.git
cd typescript-monorepo-starter
rm -rf .git
lerna bootstrap
Lerna allows some pretty nifty development stuff. Here’s a quick rundown of stuff you can do:
yarn start
: Run’s the yarn start
command in every project and pipe output to the console. This will do the following:
yarn build
: Build all projectslerna clean
: Clean up all node_moduleslerna bootstrap
: Rerun lerna’s bootstrap command**IF you run yarn add <module>
or npm install <module>
from inside a project folder, you will break your symlinks.** To manage package modules, please refer to the following instructions:
To add a new npm module to ALL packages, run
lerna add <module>
To add a new npm module(s) to just one package
lerna add <module> --scope=<package-name> <other yarn-flags>
# Examples (if your project name was `nest-starter`)
lerna add classnames --scope=@nest-starter/api
lerna add @types/classnames @types/jest --scope=@nest-starter/api --dev
Unfortunately, there is no lerna remove
or lerna uninstall
command. Instead, you should remove the target module from the relevant package or packages’ package.json
and then run lerna bootstrap
again.
Reference issue: https://github.com/lerna/lerna/issues/1229#issuecomment-359508643
None of the packages in this setup are ever published to NPM. Instead, each shared packages’ (like shared
and core
) have build steps (which are run via yarn prepare
) and get built locally and then symlinked. This symlinking solves some problems often faced with monorepos:
This project works great with WebStorm when opened from the root, this means all imports, Go to should work correctly when navigating between packages.
You are welcome.
Build the docker image:
docker build -t api -f Docker.api .
Run the Docker Container:
docker run -p 3000:3000 api
A LOT of this has been shameless taken from palmerhq/monorepo-starter.