3 ms·
has anyone aliased npm to run nvm first, and then run npm, passing in the arguments? or have people made nvm run when their system or terminal window starts so
by vmception 6y ago
has anyone aliased npm to run nvm first, and then run npm, passing in the arguments?
or have people made nvm run when their system or terminal window starts so that they don't have to remember to do it
- aphexairlines 6y agoYou can run nvm as part of your prompt so you pick it up when you cd into a directory with an nvmrc. In your bash_profile: UPDATE_NVM='[ -e .nvmrc ] && [ v$(<.nvmrc) != $(node --version) ] && nvm use' PROMPT_COMMAND="$UPDATE_NVM; ...other prompt commands..."
- mikewhy 6y agoWe combine direnv with a .nvmrc
- jessaustin 6y agoI use "n", not "nvm". No futzing around with .bashrc, just put stuff in /usr/local as God intended. https://www.npmjs.com/package/n https://www.npmjs.com/package/n
- iaml 6y agoI use nix (nix-shell) for that, it's basically universal package and env manager. You create a config file, put it in directory, and wherever you are in that directory doing `nix-shell` will put you in correct env, not just in js. You could also script it basically however you like.
- mekster 6y agoDoes that work fine in cron and other way of invoking programmatically? Many of these version managers always simply can't be involved outside interactive shells because they require unit script to be loaded first.
- iaml 6y agoI did not need to work with this use case, but from what i understand about it, you configure cron in nixos in a declarative way and nix configures cron[0], but you will most likely see no issues with scripting it anyway, there's a whole language and it can interop with other languages [0] https://nixos.wiki/wiki/Cron https://nixos.wiki/wiki/Cron
- Kaze404 6y agoI use asdf-vm, which automatically sets up your binaries when you enter a directory that needs them (provided they're set / described on a .tool-versions file). It's really neat, especially because you can check the tool-versions file into version control.
- finder83 6y agoWith fnm, you can use a .node-version file that auto-switches to the correct version when you change directories to the project.