惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
TaoSecurity Blog
TaoSecurity Blog
博客园_首页
Vercel News
Vercel News
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Exploit Database - CXSecurity.com
量子位
Project Zero
Project Zero
A
Arctic Wolf
小众软件
小众软件
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
P
Privacy & Cybersecurity Law Blog
Security Latest
Security Latest
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
Schneier on Security
Schneier on Security
The Hacker News
The Hacker News
K
Kaspersky official blog
C
Check Point Blog
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
人人都是产品经理
人人都是产品经理
AI
AI
Cisco Talos Blog
Cisco Talos Blog
MyScale Blog
MyScale Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
S
Schneier on Security
P
Palo Alto Networks Blog

Ben Frain

So, you want a React modal that uses the <dialog> element and transitions in AND out? Scroll indicators on tables with background colours using animation-timeline Review: SoundPEATS Clip1 Open ear clip-on headphones VS Code – highlight just the active indent guide Review: MoErgo Go60, a split ergonomic and fully programmable keyboard Review: Kinesis mWave mechanical ergonomic and programmable keyboard iOS26 Safari theme-color/tab-tinting with fixed position elements is a mess New Book: Responsive Web Design with HTML5 and CSS, 5th Edition Use @supports with a proxy feature/value for features you can’t test for (@starting-style) First adventures in View Transitions Review: Benq Screenbar Pro and Halo lightbars. The kit you never knew you needed! Center items in a container, and make then left aligned when they overflow A single element CSS donut timer/countdown timer, that can sit on any background Review: Open Ear Headphones – Bose Open Ultra v Huawei FreeClip In search of the perfect autocomplete for CSS Review: Keychron Q14 Max Alice 96 Key mechanical keyboard NEW VIDEO COURSE: Responsive Web Design with HTML5 and CSS Is CSS Grid really slower than Flexbox? Review: Advantage360 Pro Signature Edition 2024 mechanical ergonomic keyboard More Keys or Fewer Keys for mechanical keyboards Yes! You can use position: sticky and overflow together Neovim – how to do project-wide find and replace? Review: Keyboardio Model 100, split, wooden, mechanical keyboard Struggling to learn SwiftUI How to create rounded gradient borders with any background in CSS How to get equal size icons in the cmp completion menu of Neovim with Kitty terminal Review: Dygma Defy, split, mechanical, programmable ergonomic keyboard What’s the best way to reset WAAPI chained animations? Using CSS @property inside shadowRoot (web components) workaround Dynamically create a ref for items when iterating over them in lit.dev templates Selecting and pausing running animations in Lit Web Components New Web APIs — a popover on top of a dialog element can’t be interacted with? Review: ZSA Voyager, split, mechanical keyboard Russel Brand, narcissism, and a sadly common pattern… When it comes to text editors, I feel like Goldilocks Simple settings for writing and converting markdown with Sublime Text Review: The ZSA Platform tenting kit for the Moonlander keyboard Logitech MX Master 3/3s scroll wheel fix Building a line graph with CSS clip-mask Review: Dell 6K 32″ Monitor U3224KBA I broke my keyboard! Swapping the key switches in the Kinesis Advantage360 Pro HUGE macOS Productivity boost: Set-up simple, keyboard only, instant App switching and arrangement Adding to $PATH for a central location for Neovim/NPM tools Neovim Power Tips: Volume 2 Review: MoErgo Glove80, split, wireless, columnar ergonomic keyboard with RGB Review: Kinesis Advantage 360 Pro — split ergo mechanical keyboard Review: Dactyl Manuform – an ergonomic, custom built mechanical keyboard How to animate along an SVG path at the same time the path animates? Getting the context of Web Components (lit)
Managing multiple versions of node, without NVM or additional tools
Ben Frain · 2024-10-21 · via Ben Frain

So, you are in a situation where you have to use specific versions of Node, but don’t have access to NVM or N.

Its a pain to do the clicky-clicky installer everytime and re-install. You want a quicker way of loading the relevant version.

The crux of this approach is installing two or more different binaries of Node into different folders on your system and then using an alias in your shell to update the path so you can swap between them. A way to point your system to different versions if you will. Another dev (Hi Sam!) gave me the idea and I’m just writing out the detail here for future reference.

Practically, you will be able to enter nr in your Terminal to switch to Node v22.9.00 for your Node React project, or ns to switch to an older version of Node to support an older Svelte project that needed v10.9.3, or whatever. Obviously the names, commands, and versions will be particular to you and your projects.

I’m on macOS here so imagine Linux will be similar, not sure on Windows, sorry.

Download the binaries

Head over to https://nodejs.org/dist/ and click on the first version of Node you are interested in. For example, I wanted v22.9.0 so went to https://nodejs.org/dist/v22.9.0/. Then you want to download the relevant binary so get the *.gz file that matches your system. I’m on macOS Apple Silicon, so downloaded https://nodejs.org/dist/v22.9.0/node-v22.9.0-darwin-arm64.tar.gz.

Note, you don’t want the download that includes the source code. When you have extracted the file you download, in the next step, when you extract the contents, there should be a bin folder. If not, you have likely downloaded the source code by mistake

Now you need to repeat that process for each version you need. For the sake of explanation I have also downloaded node-v10.15.3-darwin-x64.tar.gz.

Move the gz files somewhere practical

I wanted my two (or more) versions of Node stored in folders out of the way but somewhere sensible, so put them within ./local/share/, so like my v10.15.3 would be in ./local/share/node101503.

So I moved my downloaded gz files into that share folder ready for the next step. They can go pretty much anywhere on your system, that’s just where I chose.

With the gz files for Node versions in the correct folder, we extract the binary to a subfolder with tar -xzf ~/.local/share/node-v10.15.3-darwin-x64.tar.gz -C ~/.local/share/node101503 --strip-components=1. Obviously adjust the file/folder names for your scenario and repeat for however many versions you need.

Adding a shell alias to switch Node versions

So now we have two or more Node binaries installed on our system, we just need to be able to switch easily between them.

To do this we will add two alias commands to our shell. I’m on zsh so that means editing my .zshrc file.

An ‘alias’ here is just similar to a text snippet. We write something simple and human friendly in the Terminal, press enter and that runs something more geeky that the computer understands

I added these two new alias commands with other alias’s I have defined, my two aliases for this look like this:

alias ns="export PATH=$HOME/.fzf/bin:$HOME/.local/share/node101503/bin:$HOME/bin:$HOME/.local/bin:/usr/local/bin:$HOME/.local/share/nvim/spec/node_modules/.bin:~/go/bin:$PATH"
alias nr="export PATH=$HOME/.fzf/bin:$HOME/.local/share/node220900/bin:$HOME/bin:$HOME/.local/bin:/usr/local/bin:$HOME/.local/share/nvim/spec/node_modules/.bin:~/go/bin:$PATH"

However, I have other things in there, like a path to Go and other tools that my Neovim config needs. Yours may not need to be that long for each.

The way I understand it, is that you can append more paths to your $PATH by adding a colon and then the new extra path. So if you only needed to add this new Node path, your export may be as simple as:

alias ns="export PATH=$HOME/.local/share/node101503/bin:$PATH"
alias nr="export PATH=$HOME/.local/share/node220900/bin:$PATH"

Save the file, quit your Terminal or re-source the .zshrc and try your new command. After each, you can check which Node version with node -v and check where it is looking for that Node with which node.

What the path?

By adding more paths to your $PATH (yes, I know, keep up), your system can look in multiple places for the commands you are asking it to run. Think of it as the equivalent of someone asking “Where is the flat head screwdriver?”, and you can say, “It’s either in my toolbox, or I left it out on the shelf” and the system dutifully goes and checks both locations. I believe that paths near the beginning of the export take precedence over paths near the end too.

Summary

My own workplace rejected using NVM due to security concerns, so while such tools are certainly more convenient, it may not always be practical. This is a bit of work, but when done, you should now have a simple way to swap between Node versions when you need to. The aliases and Node versions are entirely up to you but the good news is you don’t need to use a further tool.