You can do a lot in Node.js and TypeScript without ever building an NPM package. But what if you find yourself wanting to pull code out to share it am

Build an NPM Package in TypeScript from the Ground Up

submited by
Style Pass
2022-06-21 13:30:02

You can do a lot in Node.js and TypeScript without ever building an NPM package. But what if you find yourself wanting to pull code out to share it amongst several Node.js projects? You may find that putting it into an NPM package is the way to go.

You could, of course, grab a starter, like this one or that one or maybe this other one. They all do useful things, and I recommend studying them when you have some grounding.

But there is so much going on that it’s really difficult to divine what the important bits are. The best way to really understand something in software is to build it up from the ground up.

We’ll be using CommonJS instead of the newer kinds of modules for this example. It works with Node.js out-of-the-box and is generally the easiest to work with.

As you look through this, apart from a few other development niceties, you may notice one other thing — hello-cli/package.json. I didn’t create this file by hand.

Leave a Comment