Template for new libraries based on Typescript with the Best Practices and Ready for Production
Starting a new library for NodeJS can be a bit frustrating, there are a lot of things to consider if we want to have a really good starting point where later we can iterate.
The main objective of this template is to provide a good base configuration for our NodeJS libraries that we can start using and move to production as soon as possible.
- 🐳 Fully dockerized project ready to develop in the library.
- 👷 Use SWC for running the tests of the library.
- 🐶 Integration with husky to ensure we have good quality and conventions while we are developing like:
- 💅 Running the linter over the files that have been changed
- 💬 Use conventional commits to ensure our commits have a convention.
- ✅ Run the tests automatically.
- ⚙️ Check our library does not have type errors with Typescript.
- 🙊 Check typos to ensure we don't have grammar mistakes.
- 🧪 Testing with Vitest
- 📌 Custom path aliases, where you can define your own paths (you will be able to use imports like
@/src
instead of../../../src
). - 🚀 CI/CD using GitHub Actions, helping ensure a good quality of our code and providing useful insights about dependencies, security vulnerabilities and others.
- 🤖 ChatOps approach to help creating release candidates, getting help and more things. Here is an example.
- 🥷 Fully automatized release process. You just need to merge into
main
branch using conventional commits and that's all. Automatically we will:- 📘 Update library version
- 📍 Create the tags associated to your change
- 📝 Update the changelog
- 📦 Create a release
- ☁️ Publish the new version to NPM
- 🐦🔥 Use of ESModules instead of CommonJS, which is the standard in JavaScript, while allowing clients to use the library regardless of whether they use ESModules or CommonJS.
Are you thinking in start some new service in the NodeJS ecosystem? If you like this template there are others base on this you can check:
- Template for new Typescript Express Services
- Template for new NestJS Services
- Template for new GitHub Actions based on NodeJS
The library is fully dockerized 🐳, if we want to start the app in development mode, we just need to run:
docker-compose up -d
This development mode with work with hot-reload and exposing a debug port, the 9229
, so later we can connect from our editor to it.
Now, you should be able to start debugging configuring using your IDE. For example, if you are using vscode, you can create a .vscode/launch.json
file with the following config:
{
"version": "0.1.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to docker",
"restart": true,
"port": 9229,
"remoteRoot": "/app"
}
]
}
When you want to stop developing, you can stop the project running:
docker-compose down
npm run build
If you want to run the tests of the project, you can execute the following command:
npm run test
To run the linter you can execute:
npm run lint
And for trying to fix lint issues automatically, you can run:
npm run lint:fix