Realm-cli not being recognized despite being installed

I’m building an app and started up utilizing MongoDB, Atlas and Realm.

I’m running the tutorial on how to setup the backend for Realm here:
https://docs.mongodb.com/realm/tutorial/realm-app

I ran
npm install mongodb-realm-cli --save (i didn’t want to install globally) and according to my package.json file, as well as the log in my terminal, the dependency installed. In the correct path, and this was my log output:

downloading "realm-cli" from "https://s3.amazonaws.com/realm-clis/realm_cli_rhel70_102ae6146263d9849ef38ae9ef46bcaa739c215d_20_11_04_18_45_24/windows-amd64/realm-cli.exe"
downloading "transpiler" from "https://s3.amazonaws.com/realm-clis/realm_cli_rhel70_102ae6146263d9849ef38ae9ef46bcaa739c215d_20_11_04_18_45_24/windows-amd64/transpiler.exe"
Received 11426 K total.
Received 32250 K total.
npm WARN eslint-config-react-app@5.2.1 requires a peer of eslint-plugin-react-hooks@1.x || 2.x but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\jest-haste-map\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ mongodb-realm-cli@1.2.0
updated 1 package and audited 1665 packages in 23.142s

However, when I run – realm-cli --version, the terminal is telling me that it is not recognized as an internal or external command, operable program or batch file.

The tutorial documentation doesn’t appear to cover this, so I’m at a loss.

1 Like

the command “npm install mongodb-realm-cli --save” just add it to the project and package.json you are in that folder, if you want to install it locally you will find it only on that node_module/.bin folder and you could use it in the ‘scripts’ section probably but you will never be able to use it just writing realm-cli in the console because for that you will need realm-cli to be installed in /usr/bin or similar in the case of mac and not sure about windows.

then, install it globally if you really want to use it writing realm-cli in the terminal or move to node_module/.bin and use it from there but will be uncomfortable.

more info here: node.js - How to use executables from a package installed locally in node_modules? - Stack Overflow

Actually this is pretty easy to do since npm version 5.2.0.

If you click on the stackoverflow article linked above by Juan_Jose_N_A, one answer describes that you can run commands found in your local installation in node_modules simply by prepending npx before your command. So to run realm-cli, simply run:

npx realm-cli --version

1 Like

Thank you. This worked to me. Also I noticed that every command that related to realm-cli needed to add npx to work on my end. For ex: realm-cli login --api-key <public API key> --private-api-key <private API key> will run command not found; npx realm-cli login --api-key <public API key> --private-api-key <private API key> will successfully logged in.
Do you know why?. I’m using Ubuntu on windows.

I think you just always have to prepend npx before a command when the module is installed locally rather than globally. It just tells npm where to find the module (i.e., it tells it to look in your local node_modules folder).