Using NPM Packages
Adding NodeJS to a project
For that open your projects
default.nix and add
otherDeps = p: with p; [ # Native dependencies, e.g. imagemagick nodejs ];
Now you need to rebuild your local dev environment:
nix-shell --run 'make -B .envrc'
After that, you have
npm available in your project.
While nix can theoretically also install NPM modules, it’s easier to just use NPM directly. Otherwise, you will spend lots of time with nix-related issues. Because
npm are managed by nix we still have reproducible builds. Every developer on your team will use the same NodeJS and NPM version.
Before we can install dependencies, we need to generate a
package.json and the
package.lock to your git repository.
Installing NPM modules
Now we can just install node modules as required by calling
npm add tailwindcss postcss autoprefixer