Post

Fnm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
choco install -y fnm
fnm install --lts

**還要shell setup 後才可用**
git for windows in cmder:
add 
  eval "$(fnm env --use-on-cd --shell bash)"
in ~/.bashrc
reopen cmder

WinCMD:
1.
; Run a command when CMD.exe starts
[HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
"AutoRun"=%USERPROFILE%\autorun.cmd

or

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d @^%USERPROFILE^%\autorun.cmd" "2^>NUL /f

2.
@echo off
:: for /F will launch a new instance of cmd so we create a guard to prevent an infnite loop
if not defined FNM_AUTORUN_GUARD (
    set "FNM_AUTORUN_GUARD=AutorunGuard"
    FOR /f "tokens=*" %%z IN ('fnm env --use-on-cd') DO CALL %%z
)

   https://github.com/Schniz/fnm?tab=readme-ov-file#shell-setup

ref
cmder in C:\tools\Cmder
.bashrc
https://github.com/cmderdev/cmder/issues/565


It has a “default” version which is global and it plays the role of fallback in case some project doesn’t have a specified Node.js version.

The other cool feature of FNM is the auto-switching of Node.js version based on the folder you’re in, but you have to do some configuration for it.

We switched between two projects, and the Node version automatically changed based on the .node-version file inside those projects.

You must install the required Node.js version on a machine to make auto-switching work properly.

The other thing to remember is that it can detect node versions only from extra files you create in a project. Those files are .node-version or .nvmrc.

https://pavel-romanov.com/5-node-version-managers-compared-which-is-right-for-you#heading-fast-node-manager-fnm

Note that you can bypass fnm and use the system wide installation of Node on your system (if any) by using the system:

1
fnm use system

How to attach a Node version to a project

Adding a .node-version to your project is as simple as:

$ node --version
v14.18.3
$ node --version > .node-version

自動切換 Node 版本

你只需要把 .bashrc 檔案裡面的

1
2
eval "`fnm env`"

改成

1
eval "$(fnm env --use-on-cd)"

ref:
enabled them in the shell setup by adding the following flags to the fnm env command:

  • --use-on-cd: This flag tells fnm that when you cd into a project root directory, it should automatically use the Node of version specified in .node-version(or .nvmrc).

https://www.freecodecamp.org/news/fnm-fast-node-manager/

ref
https://blog.kurtstories.com/post/fnm-intro/

--

Comments powered by Disqus.