degit
is an npm package, that when given a repository name, downloads the contents of the repo but not the .git
folder, hence you will get the code, but will start with a clean git history. tiged
is a community maintained fork of degit with equivalent API, but better long term support.
To download the template run:
npx tiged https://github.com/minyma-technologies/typescript-express-starter.git <target-folder>
You can instantiate a GitHub repository with a starting template by navigating to this repo and hitting "Use this template" in the top right corner. This will create a remote repository, which you can the clone locally.
cd <target-folder>
- install dependencies:
npm install
- generate Prisma client:
npx prisma generate
- synch Prisma with db:
npx prisma migrate dev --name init
- run dev server:
npm run dev
cd <target-folder>
- build the Docker image:
docker-compose build
- launch the containers:
docker-compose up
exec
into the server container:docker exec -it typescript-express-prisma-starter_express_1 sh
- run the prisma initalization:
npx prisma migrate dev --name init
This template is very based. It includes:
- Typescript, strictly, as the language
- Express as the web framework
- Prisma as the ORM
- zod for API schema validation
- JWT for auth
- ESLint for linting
- Prettier for style checking
- Jest for testing
- Husky for pre-commit hooks
- Postgres as preconfigured database. This can be changed easily, by changing the database connection url in .env (see .env.example). For more details go here
- A database setup. Edit
prisma/schema.prisma
to update the model. - A User model with username and password
- Register endpoint with password hashing via
bcrypt
, at/api/auth/register POST
- Login endpoint which cheks the hashed passwords and yields a
jwt
token atapi/auth/login POST
- GitHub Actions config for lint, test and coverage
- Pre-push git hooks to lint code before publishing changes
While it is possible to interact with your chosen database via their provided CLI or GUI client, prisma provides an easy-to-use GUI client out of the box. To access it, simply run npx prisma studio
, then navigate to localhost:5555
in your browser.
- edit
prisma/schema.prisma
, to update the data models as needed. - run
npx prisma migrate
to apply the changes.
- edit one of
config/<environment>.ts
. - use
import config from 'config'
to access configs - access newly added fields via
config.get('foo.bar.baz')
- note that the config loaded depends on
NODE_ENV
env var - make sure to add secrets as env variables in the config files
- this repo uses husky to enforce certain rules before changes are pushed to remote
- namely, after the
push
command is issued:npm lint
is ran, if there are lint issues, the push will abort.npm test
is disabled by default, go to.husky/pre-push
to enable
- test and coverage checks are run within the GitHub CI, and are enforced (or not) by the repository maintainer pre-merge.
- this allows WIP branches to be pushed without being blocked by a coverage threshold too high, or by temporarily failing unit tests.
- there are no pre commit hooks. Developers should be able to make as many commits, as they want locally. Commits should be squashed upon merge, hence only the last commit message has to confirm to commit message conventions.
- update
docker-compose.yml
to automatically runnpx migrate
- secret detection pre-commit hook
- API example tests