NPM, package.json, best practice recommendation

Hi!

I want to play with some ECMAScript programs available in NPM (I don’t know the exact terminology, let me list node.js, package.json, etc).

What is the best way to do this in NixOS? I distrust NPM so that’s why I am trying to use NixOS as a clean environment to protect myself.

Cheers,
Yasu

:eyes: found this link Reimplement `npm install -g` with nix and bash — nick novitski

idk if that is the best way …

see also : GitHub - svanderburg/node2nix: Generate Nix expressions to build NPM packages

1 Like

Thank you, well, I am not quite familiar with NixOS anyway, so let me start with Haskell + NixOS. Hopefully, Haskell is “mainstream” in NixOS so I will get more insights into how to use Nix packaging systems when other people use other managers such as stack.

Then I will get more insights into how to use Nix instead of NPM?

There is npm2nix and yarn2nix. You create package.json and then use one of these to generate nix expression.

Let me know if you’re still hung up on this. I got ECMAScript set up a few weeks back for some WebGL stuff. I’d be happy to help but don’t want to do a whole write-up if you’ve already resolved this. :upside_down_face:

1 Like

hello .
how use nix-shell for install npm packages and why need use npm2nix.what is diffrence .

i use node2nix for install packages but need edit . no easy way in nix/nixos install node,python ,… packages/libs

with nix-shell, you get to have access to the internet, so you could just do something like:

nix-shell -p nodejs --run "npm install"

and it will work fine, as you’re just using nix to bootstrap the dev environment

that’s much more invovled, and you’ll probably have to sue node2nix to solve the issues.

For python, you can take a look at https://github.com/NixOS/nixpkgs/blob/5622b6b6feb669edc227aaf000413d5b593d4051/doc/languages-frameworks/python.section.md#ad-hoc-temporary-python-environment-with-nix-shell if your python env is static.

Or you can look at https://github.com/NixOS/nixpkgs/blob/5622b6b6feb669edc227aaf000413d5b593d4051/doc/languages-frameworks/python.section.md#how-to-consume-python-modules-using-pip-in-a-virtual-environment-like-i-am-used-to-on-other-operating-systems if your want to use a venv like python dev env

2 Likes