how to display npx's executed binary path? - node.js

I have a yarn-workspace with different packages installed different versions of the same cli tool.
assume it is called the-cli
then whe I do npx the-cli, what option can I add to make npx print out the path for executed the-cli, so I know if it is picking up the right version. kind of like which the-cli

Related

NVM for windows - ability to specify specific version without switching

I've installed NVM for windows, so I can switch between different versions of node when I have to. However, I have a need to be able to call one version of node / npm WITHOUT having to switch
For example, right now I have 2 versions of node installed: 10.17.0 and 8.9.1. I can easily switch between them using nvm use 10.17.0 or nvm use 8.9.4, and after either of those commands, when I run node ./app.js or npm install package, it uses the expected version of node / npm to do what I'm asking
But I want to create a situation where I can avoid switching, and instead I can just type node10 ./app.js or npm10 install package, and it uses the version I specify
Now, I've done a bit of research myself about what it would take to do this, so I'll lay that out and hope that someone has some advice because they've done something similar.
First of all: nvm installs both versions of node in a specific place, and that place should stay static and unchanging. I can find the 8.9.1 versions of node and npm here: C:\Users\SamuelR\AppData\Roaming\nvm\v8.9.1
I can find the 10.17.0 versions here: C:\Users\SamuelR\AppData\Roaming\nvm\v10.17.0
When I use nvm use 10.17.0, what it does is it changes a symlink at C:\Program Files\nodejs, and it points it to whichver of those two folders I specify
So my idea to make node8 / node10 and npm8 / npm10 commands work was this:
In some folder in my PATH, I was going to create 4 .bat files, node8.bat npm8.bat node10.bat npm10.bat. For node8.bat, I was going to follow the example here:
C:\Users\SamuelR\AppData\Roaming\nvm\v8.9.1\node.exe %*, so that it always forwards all my command line arguments to the correct installation.
For npm, the file npm8.bat would have C:\Users\SamuelR\AppData\Roaming\nvm\v8.9.1\npm.cmd %*.
Maybe I'd do the same for npx. And then I'd repeat those steps for the node10.bat npm10.bat files.
Is this the right way to go about this? Does it even make sense?
Welp, nobody's giving any answers, but I've tried it myself and as far as I can tell, it works!
I'll just lay it out for total clarity here: once you have nvm working as you like, find the install directory, in my case it was C:\Users\SamuelR\AppData\Roaming\nvm
For each version of node in there that you want to make these shortcuts to, make the following files,
node{v}.bat (eg node10.bat)
npm{v}.bat (eg npm10.vat)
npx{v}.bat (eg npx10.vat)
Put them all in a file that is accessible in your PATH environment variable (I made a new folder called C:\Program Files\nodelinks and put it in my path myself)
inside node10.bat:
C:\Users\SamuelR\AppData\Roaming\nvm\v10.17.0\node.exe %*
inside npm10.bat:
C:\Users\SamuelR\AppData\Roaming\nvm\v10.17.0\npm %*
inside npx10.bat:
C:\Users\SamuelR\AppData\Roaming\nvm\v10.17.0\npx %*
As far as I can tell, it passes all arguments through as expected, there's no apparent permissions issue, it works exactly as expected.

I’d like to install and require “fs”, ”path”, and “js-yaml” in Windows 10 but only “js-yaml” led to "Error cannot find module "

 Nice to meet you. I'm a beginner in computer and these days have enjoyed your sophisticated Q&As here. This is my first question in StackOverFlow. Please forgive me when I use not common notations and unnatural English.
 I trid for several hours to install external modules in Node-Red (Node.js ?).
I’d like to install three---“fs”, ”path”, and “js-yaml”--- in Windows 10 but my trouble is that only “js-yaml” resulted in failure although the others can be successfully installed and used.
 I tried the following command…
C:\windows\system32>npm –g install js-yaml
C:\windows\system32>npm –g install fs
C:\windows\system32>npm –g install path
These commands created the modules, but only js-yaml behaved differently from the other two. After adding appropriate keys and properties such as “ fs: require(‘fs’)” to functionGlobalContext in (C:~~~/.node-red/) setting.js, I tried to start Node-Red.
When I commanded
C:\windows\system32> node-red
it returned the following errors only on js-yaml and node-red did not open. It ran successfully when I removed the term “jsyaml: require(‘js-yaml’)” from setting.js.
Error loading C:~~~/.node-red/setteing.js
Error cannot find module “js-yaml”
I’ll list reports which may be related with my problem.
*The other two (fs, path) created the folders only in the directory “C:~~~/npm/node-modules”, but js-yaml created another js-yaml file apart from there in “C:~~~/npm”.
*Perhaps I tried “npm link” command in each directory before install command. And npm link [module name] in C:~~~/.node-red directory.
*I downloaded external module (node-red-contrib-postgres) from github, which may have fs.js and path.js??
*It did not change the result to add “js-yaml” term into “dependency” in (C:~~~/.node-red/) package.json.
*I add C:~~~/npm.node_modules(got by "npm -g bin"command) to enviroment variable "PATH"
I would suggest you install them locally, not globally.
When you install npm modules globally using -g, they are stored under %APPDATA%\npm, which is user-specific, and to which Node Red may not have access, depending on how it's being run.
Have a look at Running on Windows under "Sharing Node-RED between Users" and npm-folders for further info.
Alternatively, you can also put the actual path in functionGlobalContext, which may work for you. Along the lines of:
js-yaml: require(‘/the/path/to/js-yaml’)

Error after packaging the app with electron-packager

I'm new to Electron, and I really love it so far, but I'm unable to package any of mine apps, at first I thought that it's maybe something related to my code, then I download "https://github.com/atom/electron-quick-start" run npm install and then I run "electron-packager . FooBar --platform=darwin --arch=x64 --version=0.28.2" it build the app but when I try to open it I get
so I didn't touch any code from the example, just wanted to build it and I got an error, what am I doing wrong? Thanks!
The versions of electron are moving very very fast.
And some times, they don't respect the "old" ways to do things (for example, declaring the app).
I advise you to not use the 0.28.2 version of electron but the most recent one.
It is very likely that the version of electron-prebuilt you are using to develop is much much much more recent than the 0.28.2 version. So, you are developing with something much newer, and then you are building with 0.28.2. This would cause the exact error that you are seeing, as older versions may not have had the electron module, which your code explicitly is importing. So... that is my suggestion. Change the version in your electron-packager command from 0.28.2 to something like 0.36.0. See if that works. Or better yet, use the same version as electron-prebuilt in your package.json.
This could be a combination of factors.
First, as others stated, the version of electron that you have might be newer than the one referenced in your build command. Locate the 'electron_prebuilt' folder inside your 'node_modules' folder, and examine the package.json file and make sure the version # is the same as what you are declaring in your build command.
If they are the same, then the issue might be that you have another version of electron on your computer that node is trying to use. If you installed electron via the -g option (global), check your home folder to see if there is another different version of electron. If you find one, either delete it or rename the 'electron_prebuilt' folder you find to something else. Try your build command again, and it should work now that you've eliminated the other versions of electron_prebuilt on your computer that node was referencing.
What worked for me was to move the "electron" module from "dev-dependencies" to "dependencies" in package.json. Try this and see if it works.

Yeoman hangs on line 72 of events.js, won't let me do anything

First of all, I'm running this on Windows 8.
So When I install yeoman with npm install -g yo, it seems to work fine.
Then, when I type in the command yo, I get the usual response of:
[?] What would you like to do? (Use arrow keys)
Run the Famous generator (0.2.10)
Update your generators
Install a generator
Find some help
Get me out of here!
But then when I click on, for example,
Update your Generators
I get the following:
Its the exact same error every time, and it's preventing me from using any yeoman generators, which is making it impossible then to use the new Famo.us engine.
So far, I've tried uninstalling and reinstalling Node, Yeoman, and everything in between. I've also tried it in various command prompts, including the standard Windows Command Prompt, Git Bash, NodeJS commandPrompt, and cygwin.
Does anyone know how I can fix this?
One avenue of action I've been thinking about is trying to find this events.js (or whatever other file this error is originating from) and trying to build from there.
Also, this person # Yeoman gifsicle error (and others) seems to be having similar issues, but the fixes mentioned in that question don't seem to be working for me.
Thanks!

getting node.js working

So I'm following:
http://giantflyingsaucer.com/blog/?p=894
and installing node.js.
I got up to the part with sudo make install.
It works, then it says to create a js file.
What I don't understand is where I put the sayhello.js?
Node.js looks at least for the programmer more like a interpreter. Thus, you can place your sayhello.js whereever you want and run it by executing node sayhello.js.
However, you might consider using external modules. Then you must check that they are set by full path or the relative path can be resolved from the location you execute node in.

Resources