An npm package for demonstration purposes using TypeScript to build for the ECMAScript Module format (i.e. ESM or ES Module). It can be used in Node.js and browser applications. Refer to the Snyk blog post for a full tutorial.
If you're reading/coming from the Snyk blog post that discusses both ESM and CommonJS go to the v2022-2024 branch
- Run
npm installin your terminal - Then run
npm run build - Update the
package.jsonfile "name" field with your own package name. Example@username/package-name - Create an account with npm if you don't have one already. Also be sure to enable two-factor authentication
- Sign in to your npm account in your terminal with
npm login - Run
npm publish --access=publicto publish your package
- Install developer dependencies using the following command in your terminal
npm i -D typescript @types/node - Create a
testsfolder - Create an
index.test.tsfile in thetestsfolder - Write unit tests in the
index.test.tsfile to test the code inindex.ts - Add a
"test"property in thepackage.jsonfile"scripts"object and give it a value of"node --experimental-strip-types --test" - Run
npm testin your terminal from the root folder of the project