{"id":16179331,"url":"https://github.com/1111mp/nvmd-command","last_synced_at":"2025-03-19T01:30:57.647Z","repository":{"id":190109329,"uuid":"681959810","full_name":"1111mp/nvmd-command","owner":"1111mp","description":"Provides services for nvm-desktop to manage multiple active node.js versions.","archived":false,"fork":false,"pushed_at":"2024-03-03T11:04:46.000Z","size":115,"stargazers_count":19,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-04T02:37:30.996Z","etag":null,"topics":["nodejs","nvm-desktop","nvmd","nvmd-command","version-manager"],"latest_commit_sha":null,"homepage":"https://github.com/1111mp/nvmd-command","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1111mp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-08-23T06:19:59.000Z","updated_at":"2024-04-23T12:02:56.205Z","dependencies_parsed_at":"2023-11-23T03:31:25.092Z","dependency_job_id":"f9d6124d-e542-47dc-b813-6c693a1785d4","html_url":"https://github.com/1111mp/nvmd-command","commit_stats":null,"previous_names":["1111mp/nvmd-command"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1111mp%2Fnvmd-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1111mp%2Fnvmd-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1111mp%2Fnvmd-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1111mp%2Fnvmd-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1111mp","download_url":"https://codeload.github.com/1111mp/nvmd-command/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244336140,"owners_count":20436774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","nvm-desktop","nvmd","nvmd-command","version-manager"],"created_at":"2024-10-10T05:27:12.478Z","updated_at":"2025-03-19T01:30:57.416Z","avatar_url":"https://github.com/1111mp.png","language":"Rust","readme":"# nvmd-command\n\n`nvmd-comand` is a single, fast native executable, with no external dependencies, build with Rust. A proxy for Node and Npm, through which it can intelligently (quickly) identify the correct version of the Node engine.\n\nProvides services for [nvm-desktop](https://github.com/1111mp/nvm-desktop)'s Node engine version management function.\n\nYou can also manage all versions of node directly from the command line. But if you need to download and install a new version of node, you should open the `nvm-desktop` application.\n\n## Command tools intro\n\n`nvmd` allows you to quickly manage different versions of node via the command line.\n\n```shell\n$ nvmd use 18.17.1\nNow using node v18.17.1\n$ node -v\nv18.17.1\n$ nvmd use v20.5.1 --project\nNow using node v20.5.1\n$ node -v\nv20.5.1\n$ nvmd ls\nv20.6.1\nv20.5.1 (currently)\nv18.17.1\n$ nvmd current\nv20.5.1\n```\n\nSimple as that!\n\n## Usage\n\nPlease download and install the latest release of node in the `nvm-desktop` application.\n\n```shell\n$ nvmd --help\nnvmd (2.2.0)\nThe1111mp@outlook.com\ncommand tools for nvm-desktop\n\nUsage: nvmd [COMMAND]\n\nCommands:\n  current  Get the currently used version\n  list     List the all installed versions of Node.js\n  ls       List the all installed versions of Node.js\n  use      Use the installed version of Node.js (default is global)\n  which    Get the path to the executable to where Node.js was installed\n  help     Print this message or the help of the given subcommand(s)\n\nOptions:\n  -h, --help     Print help\n  -V, --version  Print version\n\nPlease download new version of Node.js in nvm-desktop.\n```\n\nYou can list all installed versions using `list` or `ls`:\n\n```shell\nnvmd list\n# or\nnvmd ls\n```\n\nAnd then in any new shell just use the installed version:\n\n```shell\nnvmd use node_version\n```\n\nOr you can run it directly using the node version for your project:\n\n```shell\nnvmd use node_version --project\n```\n\nYou can get the version you are currently using:\n\n```shell\nnvmd current\n```\n\nYou can also get the path to the executable to where it was installed:\n\n```shell\nnvmd which 18.17.1\n```\n\n## How does it work?\n\n`nvmd-comand` does not use any fancy OS features or shell-specific hooks. It’s built on the simple, proven approach of shims.\n\nAfter installing nvm-desktop and starting it for the first time, the following files will be added to the `$HOME/.nvmd/bin` directory (Taking the macOS platform as an example, it is roughly the same on the Windows platform):\n\n\u003cimg width=\"793\" alt=\"Screenshot 2023-10-28 at 16 22 30\" src=\"https://github.com/1111mp/nvmd-command/assets/31227919/7d8a1de8-3c60-4e93-a875-657b47df9aeb\"\u003e\n\nWhen you run a `node` or `npm` command, it will eventually be executed by `nvmd`. `nvmd` will quickly identify the correct node engine version internally and then create a new process to execute the command you entered.\n\nExamples (Assume that your node version is `v20.6.1` at this time):\n\n\u003e The version number of the set `node` will be saved in the `$HOME/.nvmd/default` file.\n\nWhen you enter the `node --version` command in the terminal:\n\n```shell\nnode --version\n```\n\n- `nvmd` will actually be called to execute.\n- Inside nvmd, it will quickly find the installation directory of the corresponding version node through the set version number: `$HOME/.nvmd/versions/20.6.1`\n\n```rust\nfn get_version() -\u003e String {\n    // Find the version number set for the project\n    let mut nvmdrc = match env::current_dir() {\n        Err(_) =\u003e PathBuf::from(\"\"),\n        Ok(dir) =\u003e dir,\n    };\n    nvmdrc.push(\".nvmdrc\");\n\n    let project_version = match read_to_string(\u0026nvmdrc) {\n        Err(_) =\u003e String::from(\"\"),\n        Ok(v) =\u003e v,\n    };\n\n    if !project_version.is_empty() {\n        return project_version;\n    }\n\n    // Find the version number set for the system\n    let mut default_path = NVMD_PATH.clone();\n    default_path.push(\"default\");\n\n    let default_version = match read_to_string(\u0026default_path) {\n        Err(_) =\u003e String::from(\"\"),\n        Ok(v) =\u003e v,\n    };\n\n    return default_version;\n}\n```\n\n- Then nvmd will create a new process and add the directory where the executable file of this version of node is located to the environment variable of the new process.\n- Add env `$HOME/.nvmd/versions/20.6.1/bin`\n- Execute the `node --version` command by this new process\n\n```rust\nlet child = Command::new(exe)\n    .env(\"PATH\", ENV_PATH.clone()) // $HOME/.nvmd/versions/20.6.1/bin:$PATH\n    .args(args)\n    .status();\n```\n\n- Then get the output of the new process, wait for it to execute and finally exit.\n\n```rust\nmatch child {\n    Ok(status) =\u003e Ok(status),\n    Err(_) =\u003e Err(String::from(\"failed to execute process\")),\n}\n```\n\n- Finally output:\n\n```shell\nnode --version\nv20.6.1\n```\n\nBut the commands for `npm install packages --global` or `npm uninstall packages --global` require special handling：\n\n- When using `npm` to install packages globally, `nvmd-command` will add a shim and record the corresponding `node` version. These information will be stored in `$HOME/.nvmd/packages.json` file with the content like this (example for `npm install @vue/cli typescript -g`):\n\n![image](https://github.com/1111mp/nvmd-command/assets/31227919/b82f8ba5-dff1-4c36-a9a1-c1fbe130383e)\n\n```json\n// \"18.17.1\", \"20.5.1\" Installed in both versions\n// When `npm install @vue/cli typescript -g` is executed successfully, the following information will be recorded\n// will not be added repeatedly\n{\"tsc\":[\"18.17.1\", \"20.5.1\"],\"tsserver\":[\"18.17.1\", \"20.5.1\"],\"vue\":[\"18.17.1\", \"20.5.1\"]}\n\n// Uninstall the \"20.5.1\" version\n// npm uninstall @vue/cli typescript -g\n// The shim will not be removed because it is still referenced by \"18.17.1\"\n{\"tsc\":[\"18.17.1\"],\"tsserver\":[\"18.17.1\"],\"vue\":[\"18.17.1\"]}\n\n// Continue to uninstall the \"18.17.1\" version\n// npm uninstall @vue/cli typescript -g\n// The shim will be removed as it is not referenced by any version\n{\"tsc\":[],\"tsserver\":[],\"vue\":[]}\n```\n\nThis ensures the independence of each version of the Node engine, and they will not affect each other.\n\n## Build nvmd-command\n\n- First, you should have a Rust runtime installed locally. Please read the official guide: [rust get-started](https://www.rust-lang.org/learn/get-started).\n- Then pull the project code locally, go to the `./` folder.\n- Run `cargo build` (debug) or `cargo build --release` (release) build your executable.\n- Finally, you can find the compiled executable named `nvmd` in the `./target/release/` directory. (`nvmd.exe` on Windows.)\n\nCheck out this [documentation](https://github.com/1111mp/nvm-desktop#develop-and-build) on how to package this executable with [nvm-desktop](https://github.com/1111mp/nvm-desktop).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1111mp%2Fnvmd-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1111mp%2Fnvmd-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1111mp%2Fnvmd-command/lists"}