Install a Node.js package with npm install

default.nix:

{ pkgs ? import <nixpkgs> {} }:
pkgs.runCommand "codedown" { buildInputs = with pkgs; [ nodejs ]; } ''
  mkdir -pv $out/cache $out/bin
  npm --cache $out/cache install codedown@2.1.2 --prefix $out
  rm -rf $out/cache
  ln -s $out/node_modules/.bin/codedown $out/bin/codedown
''

To install the npm package, use nix-env -i:

$ nix-env -f . -i codedown
installing ‘codedown’