Workshop: Publishing to npm
Overview
Permalink to “Overview”In this workshop, we will learn about node modules and npm, the JavaScript package registry. We will create a simple module and then publish for the world to see. We will then learn about releasing updated packages by converting our original code from JavaScript to TypeScript.
Topics covered
Permalink to “Topics covered”- node modules
- npm
npm-cli
- Private/public packages and scoping
- Build processes
- Semantic versioning
Pre-requisites
Permalink to “Pre-requisites”In order to participate in this workshop, you need:
- an npm account
npm-cli
installed (comes with node.js)- a computer, and
- a stable internet connection
Part One
Permalink to “Part One”- What is a node module?
- Components
package.json
- “name”
- “version”
- “main”
README.md
index.js
- Making an simple module:
@<USERNAME>/utils
- Capitalize function
- Testing our module
- Preparing for release
npm version major
- Publishing our module
- Public scoped
- "private"
Part Two
Permalink to “Part Two”- TypeScript conversion
- Rename and convert to TS
- Add dev dependency:
npm i -D typescript
- Add
tsconfig.json
- “include”
- “compilerOptions”
- “target”
- “module”
- “declaration”
- Plug-in TypesScript
- Add “scripts” to package.json
- “build”: “tsc”
- Add “types” to package.json
- Add “scripts” to package.json
CHANGELOG.md
- Semantic versioning
- Preparing for release
npm version minor
- Publishing
v1.1.0