Create a consumer for your library

July 2017
On the main tutorial we've setup the library 'hwrld'. But let's say we're not comfortable publishing it to npm yet and we want to test locally how it would behave once published. Luckily, setting up a consumer for your library is really easy.

Step 1: Create a folder

If your library is contained for example in mylib, then create libconsumer next to it so your folder structure looks like this:

├── mylib
└── libconsumer

Step 2: Create a package.json

Create a package.json file. It could look somewhat like this one:

  "name": "libconsumer",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  "author": "",
  "license": "ISC"
It actually doesn't matter too much what's in there, but it needs to be present for the next step to work.

Step 3: Link your library

Now comes the magic. Go to the libconsumer directory and run

npm link ../mylib
This will create a symlink in libconsumer's node_modules to the mylib library. To read more on npm link, see the docs.

Step 4: Consume your library

Write some file(s) to consume your library. For example

import {sayHello} from 'hwrld'
You compile this simple example like this:
tsc somefile.ts
Finally you can run
node somefile.js
and in this example it should log hi to the console. And that's it!

You can now ...

Dear Devs: You can help Ukraine🇺🇦. I opted for (a) this message and (b) a geo targeted message to Russians coming to this page. If you have a blog, you could do something similar, or you can link to a donations page. If you don't have one, you could think about launching a page with uncensored news and spread it on Russian forums or even Google Review. Or hack some russian servers. Get creative. #StandWithUkraine 🇺🇦
Dear russians🇷🇺. I am a peace loving person from Switzerland🇨🇭. It is without a doubt in my mind, that your president, Vladimir Putin, has started a war that causes death and suffering for Ukrainians🇺🇦 and Russians🇷🇺. Your media is full of lies. Lies about the casualties, about the intentions, about the "Nazi Regime" in Ukraine. Please help to mobilize your people against your leader. I know it's dangerous for you, but it must be done!