Opinionated boilerplate for a Node.js TypeScript app
- Logging: winston (Slack integration)
- Config: dotenv
- Linting: ESLint (Airbnb)
- Formatting: Prettier / EditorConfig
- Testing: Jest
- Git Hooks: husky / lint-staged
- Node (v16.15.0)
- Clone the repo
- Complete steps in: Appendix > Local Development > Setup
- Use required Node.js:
nvm use
- Install dependencies:
npm i
- Set Git Hooks permissions:
sudo chmod -R +x .husky
- Create config:
cp .env-template .env
- Change your .env config file values (see Appendix > Config)
- Use required Node.js:
nvm use
- Start app in watch mode:
npm run local
When file changes are detected, the app will automatically rebuild/restart
- Check ESLint rules:
npm run lint
- Fix ESLint errors:
npm run lint:fix
- Check code formatting:
npm run prettier
- Fix Prettier formatting errors:
npm run prettier:fix
- Install nvm: https://github.com/nvm-sh/nvm
- Install the Node.js version required by this app:
nvm install
- NVM will determine the required Node version using the .nvmrc file
- NVM will install the required Node version if it isn't installed
- NVM will set your current Node version to the one required
- pre-commit: running
git commit
will triggernpm run lint:staged
which will lint all files currently staged in Git. If linting fails, the commit will be cancelled - post-commit: running
git commit
will triggergit status
after the commit completes
All the config options used by this app:
Environment Variable | Type | Description |
---|---|---|
HELLO_WORLD | string | The env value printed in Hello World! |
Environment Variable | Type | Description |
---|---|---|
LOGGER_SLACK_WEBHOOK | string | Webhook URL for logging to Slack (see Appendix > Logging > Slack) |
LOGGER_SLACK_LEVEL | string | The level of error to log to Slack |
When you want to log something in the app, import utils/logger. This uses Winston under the hood, so take a look at Winston's documentation if you want an in depth look at all the params you can pass to the logger.
Typical usage:
logger.debug("Only logged in local");
logger.info("Logged in all environments");
logger.warn("Logged in all environments");
logger.error("Logged in all environments");
The logger is configured to log to the console in every environment. It's also ready to log to Slack in addition to the console, if desired. To enable this functionality:
- Add a webhook to Slack: https://api.slack.com/messaging/webhooks
- Set the
LOGGER_SLACK_WEBHOOK
environment variable to the resulting URL - Set the
LOGGER_SLACK_LEVEL
environment variable to the desired error level you want logged to Slack (e.g.,info
)