Setup for a TypeScript Node NPM Package Project (2024)
I have built Dozens of NPM packages and have been changing my setup over time for all of them. It can get complex when you want something nice to code in and your package to be easily used by ESM and CJS projects. Not to mention the TypeScript setup.
So, let me show you how I do it…
I have also shared how to set up a Node TypeScript project in a different post that you can check.
Create a project
For example, I'll create a simple package to expose my amazing addTwo
function.
export const addTwo = (a: number, b: number) => {
return a + b
}
I'll first create a project directory and, inside, run the following commands:
#initialize an npm project
# accepting all defaults for the package.json
npm init -y
# initializse a git repository
git init
The above commands assume you already have npm
and git
installed on your machine.