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

推荐订阅源

Hacker News - Newest:
Hacker News - Newest: "LLM"
Webroot Blog
Webroot Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
N
News and Events Feed by Topic
H
Hacker News: Front Page
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
SecWiki News
SecWiki News
N
News | PayPal Newsroom
T
Tor Project blog
W
WeLiveSecurity
A
Arctic Wolf
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Secure Thoughts
月光博客
月光博客
AWS News Blog
AWS News Blog
D
Docker
C
CERT Recently Published Vulnerability Notes
MyScale Blog
MyScale Blog
Google Online Security Blog
Google Online Security Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss
I
InfoQ
人人都是产品经理
人人都是产品经理
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
博客园 - 【当耐特】
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
Recorded Future
Recorded Future
罗磊的独立博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
D
DataBreaches.Net
S
Security Affairs
WordPress大学
WordPress大学
T
Threatpost
Microsoft Security Blog
Microsoft Security Blog
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
B
Blog RSS Feed
Project Zero
Project Zero
P
Proofpoint News Feed

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.