This is my workflow for integrating pre-commit hooks for Node.js (NPM) projects. I combine this with my Oxc Workflow.
What is a Git pre-commit hook?
A pre-commit is a type of Git Hook that runs before each commit. It can help with verifying code standards (linting, formatting, testing etc.).
Pre-commit tools
pre-commit
A tool written in Python, though can be used with projects in any language. Can be configured to run many hooks including pre-commit/pre-commit-hooks and Gitleaks. I have used this tool and like it for Python and other projects, though for Node.js projects, I prefer the options below.
Husky
A pre-commit hooks tool written in JavaScript. I prefer this tool for Node.js projects since it can be easily integrated in package.json scripts.
lint-staged
Another tool that’s written in JavaScript, to help run checks against staged files (see Guide below). Lint-staged does not configure git pre-commit hooks on its own, but can be combined with Husky.
simple-git-hooks
Another git hooks manager written in JavaScript. Use to be more lightweight than Husky, but newer versions of Husky closed the gap.
Guide: Husky + Lint-staged + Oxc workflow
Configure
oxlintandoxfmtbased on my Oxc Workflow.Install
devDependencies:
npm install --save-dev husky lint-staged- Initialize
husky:
# Installed
./node_modules/.bin/husky --init# Not installed
npx run husky --init- Configure
lint-stagedto run Oxc andtscchecks:
[/**
* @filename: lint-staged.config.js
* @type {import('lint-staged').Configuration}
*/
export default {
'**/*.[jt]s?(x)': [
'oxfmt',
'oxlint --type-aware --type-check --fix',
],
'**/*.ts?(x)': () => 'tsc -p tsconfig.json --noEmit',
}Can be further configured, but this is a good start for a project using TypeScript and Oxc.
- Configure
huskyto runlint-stagedas a pre-commit hook:
npm exec -- lint-staged --config lint-staged.config.js- Add a
preparescript inpackage.json:
"scripts": {
"prepare": "husky"
},husky --init.




