npm link: What the first `npm link` really does and how it can also be used

Published 2018-11-28, 13:39

There are loads of articles about npm link, how it works (npm link in library dir, then npm link library in project that should use that local library as a dependency) and what it can be used for (linking to a local folder for a dependency instead of having a npm downloaded version in node_modules).

But most skip over or only scrape what the first of the two steps really does – and how that can be used besides the default use case.

TLDR: npm link not only creates a symlink to the library in the global node_modules (that can be used in the second step of npm link ...), but also makes the library main script or binary accessible via a global npm module, similar to what happens when you npm install -g something.

The details:

When you run npm link as the first step of the two-step linking process, you create a „symlink in the global folder„.

Let’s follow the individual sub steps:

λ npm list -g --depth=0 
C:\Program Files\nodejs
+-- npm@6.4.1

We start in a specific folder (C:\Projects\Cordova in my example) and check our globally installed packages: We have nothing besides npm installed on this machine.

λ cd cordova-paramedic 
λ npm link
removed 1 package in 3.649s
C:\Program Files\nodejs\cordova-paramedic -> C:\Program Files\nodejs\node_modules\cordova-paramedic\main.js
C:\Program Files\nodejs\node_modules\cordova-paramedic -> C:\Projects\Cordova\cordova-paramedic

Now we switch the directory of our library that we want to link, cordova-paramedic here. We run npm link which creates two symlinks:

  1. C:\Program Files\nodejs\cordova-paramedic -> C:\Program Files\nodejs\node_modules\cordova-paramedic\main.js
  2. C:\Program Files\nodejs\node_modules\cordova-paramedic -> C:\Projects\Cordova\cordova-paramedic

The first one is a symlink for the „binary“, the main script, of our library.
The second is a symlink for the whole library into the global node_modules.
(C:\Program Files\nodejs\ is our global node/npm folder on this machine)

That first symlink is not mentioned in most of the articles about npm link on the web as the example libraries being linked don’t include a main script in their package.json.

λ npm list -g --depth=0
C:\Program Files\nodejs
+-- cordova-paramedic@0.6.0-dev -> C:\Projects\Cordova\cordova-paramedic
`-- npm@6.4.1

When we check the globally installed modules again, we see that our library was added to that list.

So not only can we now use npm link cordova-paramedic, the second command in the npm link two step process, to add this library to any project from our local checkout – but we can also use it as a global command cordova-paramedic!

λ cordova-paramedic
Error missing args.

So using npm link you can not only link local development versions of libraries to use in another project, but you can also create a global command that uses a local version of your command code. This is very useful when developing such a library.

Android Emulator: PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value

Published 2018-11-16, 17:38

Debugging and fixing a broken Android SDK setup is always „fun“ – especially on a CI environment where you don’t control the actual installation.

It gets worse when all the StackOverflow answers and other Google results for the error you are getting are basically „I executed some slightly related, but otherwise random commands, and after that it worked“.

In my specific case I was getting this error message when trying to start an Android Emulator:

PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value

It was really hard to find out what „AVD system path“ actually meant and how my ANRDOID_SDK_ROOT could be connected to that.

So to maybe make this search a bit easier for future people having this problem, I write a solution down here:

Continue reading Android Emulator: PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value…

Azure Devops Pipelines: Software available on Microsoft hosted agents

Published 2018-11-14, 15:27 contains links to READMEs on GitHub that list the available software

How to install Laravel (5.6) on Uberspace (7)

Published 2018-07-16, 12:57

Laravel is a great PHP framework, and Uberspace is a great and nice PHP host. Why not mix both?

Installing Laravel on shared hosting – which Uberspace still is despite the shell access etc. – can be difficult, especially because of public folder that is used to respond to requests instead of the project root.

Here are the basic instructions for getting a new Laravel project to respond to calls of your <username> domain:

  1. Switch folder to /var/www/virtual/<username>.
  2. composer global require "laravel/installer" to install the Laravel Installer.
  3. Create a new Laravel project: laravel new <projectname>.
  4. Delete /var/www/virtual/<username>/html (make sure it is empty, or just rename it maybe) and replace it with a symlink from html to <projectname>/public.
  5. The default Laravel start page should now be available at your <username>

To be able to use the database in the project, you have to make some changes:

  1. Get your generated MySQL password from ~/.my.cnf.
  2. Update the .env file in your Laravel project:
    Username and database should be changed to your username, the password to the one you just retrieved.
  3. Caution: At the time of writing Uberspaces uses MariaDB 10.1.34 (find out by using the command mysql -v). Laravel needs some tiny changes if you work with MariaDB <10.2.2:
    • Edit the app/providers/AppServiceProvider.php file and add the following:
      use Illuminate\Support\Facades\Schema;
      public function boot()

      (Add both the method call and the import!)

  4. Now you can run php artisan migrate in your Laravel project to create the default tables.

Of course you probably don’t want to host your project at your domain, not create a new project but check out your already developed project from git, and also not use the default database – but I am sure you can find your way from here.

How to Install Ruby with rbenv on Ubuntu 16.04

Published 2017-12-13, 14:48

Each time I have to install Ruby + rbenv + bundler manually on a Ubuntu machine I somehow mess it up and have to google for a tutorial, then try some until I find a working one.

This one here did work perfectly yesterday, when it was time to do it once again:

How to create a macOS High Sierra VM with VirtualBox

Published 2017-11-24, 00:43

Unix command line: How to output to command line and file at the same time

Published 2017-11-22, 12:34


foo | tee output.file

20 queries. 0,974 seconds.