How to run 'node' and 'npm' commands outside of the nodejs folder that was downloaded from nodejs.org - node.js

So, I installed node.js in a computer and saved the nodejs folder in program files folder.
However, I am not able to run an node or npm command in cmd unless the path I am in is either Program Files or in Program Files. How do I use the commands everywhere?
Thanks in advance!

Well, you need to add the directory to your Path environment variable.
Usually, nodejs does this for you during the installation but if you forgot to select that option, you can always add it manually:
Open the Start menu in Windows, type "env" and select "Edit the system environment variables", you end up on the "Advanced" tab of the System properties dialog. On this tab, you can see four buttons, the last of which says "Environment variables"
Click that button to open the environment variables dialog, in which you will see two panels, the upper being the variables for your current user, the lower one being the system-wide variables.
In both panels, you can find a variable named "Path". Select the one you want to edit (user-wide or system-wide) and click on "Edit".
In the Edit dialogue, you see a list of Windows paths currently in the "Path" variable. You'll want to click on "New", which creates a new entry and then click on "Find..." to open a window to let you select a folder on your system. There, find and select the folder you installed nodejs to, that is, the folder containing the "node.exe" executable as well as the "npm" and "npx" scripts.
Save everything, fire up a CMD or PowerShell and test by entering node --version
Alternatively, just re-install node and during the installation, watch out for a checkbox say something the likes of "Add installation folder to %PATH%".

If you use Windows.
From www.howtogeek.com:
The Windows System PATH tells your PC where it can find specific directories that contain executable files. ipconfig.exe, for example, is found in the C:\Windows\System32 directory, which is a part of the system PATH by default. When you type ipconfig into a Command Prompt, Windows doesn’t need to know where that EXE is–it’ll check all the folders in its PATH until it finds the right one.
So we have to add the path of the nodejs installation folder(which contains node.exe and npm.exe files) in the path environment variable.
So windows button on keyboard and search edit the system environment variables.
Open it and then in the System Variables settings search Path
Click edit and then insert in a new line:
C:\Program Files\nodejs\
Or where you have installed node.
(if you go in this dir you see the npm.cmd and node.exe files).
Restart.
Now try npm or node commands on cmd everywhere you want.

Related

Windows Folder Shortcut of an Electron App - get the path of that folder?

TL;DR
I want to open my Electron App through a Windows Folder Shortcut (right-click on any folder and click Run In My Electron App), and get the folder path that initiated the app.
I managed to create the shortcut using windows Registry, but I can't find a way to get the path of the folder that initiated the app. (in the shortcut, "Temporary")
So in the above shortcut, the goal is to know the path of F:\ePC\Libraries\Videos\Loom\Temporary inside the electron app. (and the path should always be matching the folder that initiated the app).
A real-world working example: Just like when using WinRAR, you can right-click on a folder and click "Add to archive..." - the WinRAR app knows the path of the folder that has been right-clicked on. (Kind of like "open file with", but "open folder with").
Another real-world example that works with Electron is Visual Studio Code, you can right-click on a folder and click "Open With Code". How did they do that?
My Attempt
I tried to look over the documentation of Electron but only found a way to get the path of the EXE file, but not the folder that excecated that file using the Windows folder shortcut.
I tried also process.argv but it gives me the path of the exe file, and not the initiating folder.
Steps to reproduce the my attempt and test it yourself:
Get the repository and clone it. (It only has 3 files: index.js, index.html and package.json).
Open that folder in the command line and run npm install
Export the electron app by running npm run package-win. this should export the exe file to [relative app path]/rlease-builds/windows-folder-electron-shortcut-win32-ia32/windows-folder-electron-shortcut.exe.
To add the windows shortcut for the app: In the windows, registry create this:
HKEY_CLASSES_ROOT\Folder\shell\Run In My Electron App\command
Here's a step by step:
4 a. Open "Registry Editor" in Windows.
4 b. Head over to HKEY_CLASSES_ROOT\Folder\shell and create a new folder called "Run In My Electron App"
4 c. Inside the created folder, create command folder.
4 d. Double click on the default value and change it to the full path of the exe file.
(In my case the default value is: C:\Users\elron\apps\windows-folder-electron-shortcut\rlease-builds\Paste Folder Icon-win32-ia32\Paste Folder Icon.exe. Make sure that the path is YOUR path of .exe file of the exported app.)
When done with step 4, It should look something like this:
Result:
When running the app through a folder shortcut, it will give you the path of the EXE as expected, but not the path that initiated the app as shown in this screenshot:
And now you can test it.
Any help will be appreciated!
In the registry add this to your command value:
"C:\Users\elron\apps\windows-folder-electron-shortcut\rlease-builds\Paste Folder Icon-win32-ia32\Paste Folder Icon.exe" "%1"
The "%1" will pass the initiating directory to your electron application.
You can extract the directory path in your electron application like this:
const exePath = process.argv[0];
const folderPath = process.argv[1];

clasp is not recognized after installing on windows 10

I am trying to use Visual Studio Code as Google Sheets Script editor on a win 10 machine.
To make a long story short I will not describe all my steps, as I didn't really understood at the beginning exactly what I need. I also wouldn't be able to do it even I want to.
The current situation is that clasp is not recognized on the system.
These are command line results:
c:\>where npm
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
c:\>where clasp
C:\Users\XXX\AppData\Roaming\npm\clasp
C:\Users\XXX\AppData\Roaming\npm\clasp.cmd
on drive c: root (and any folder other than C:\Users\XXX\AppData\Roaming\npm\clasp) clasp is not recognized
c:\>clasp -v
'clasp' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\XXX\AppData\Roaming\npm>clasp -v
2.3.0
One suggestion I found is setting Windows user variable as follows:
SET NODE_PATH=% APPDATA%\npm
Didn't help.
npm related paths on Windows PATH :
C:\Users\XXX\AppData\Roaming\npm
I tried to add to PATH the following file path before the one above
C:\Program Files\nodejs\npm
Didn't help
Based on this post looks like npm is actually installed twice. For current user C:\Users\XXX\AppData\Roaming\npm and for all users C:\Program Files\nodejs\npm.
Maybe this is the problem.
I would like to start over from clean env.
How can I uninstall the local user npm installation on C:\Users\XXX\AppData\Roaming\npm?
You need to add path to npm in environment variables. Then it will work.
Press Ctrl+r
Write %AppData% and hit enter
You will land on roaming folder
Go to npm folder inside roaming and check if a file named clasp is there or not
If yes, then add the path to npm in environment variables
In my case the path is C:\Users\HARI\AppData\Roaming\npm

Can Gnome Builder actually produce something else than flatpaks?

I can't seem to find any documentation as to how to configure builds to produce something else than the pre-configured flatpaks. Duplicating build configurations and changing the settings doesn't seem to give me the option to produce anything else than flatpaks. Changing the application runtime to "Host System" produces only flatpaks as well. I can't even find the preliminary binaries that seem to be produced somewhere before they're packaged. What am I doing wrong?
For reference, I am using Builder 3.36. My assumption based on your post is you're looking only for your application binary, and not a way to build some other package like .deb or .rpm.
There are a few ways you can do this.
Method 1: From your Flatpak build's directory
Click the omnibar and click "build", not "Export Bundle". When it's completed, click the "View build console contents" button from the same omnibar drop down where the "Export Bundle" button is.
Look at the last lines of output in the terminal for the "flatpak build" command. Look for the "build-dir" parameter passed to this command.
The path will be something like "~/.cache/gnome-builder/projects/AppName/builds/org.your.App.json-flatpak-org.gnome.Platform-x86_64-3.34-unversioned"
Go into this directory. It will have a subdirectory "src" which has your app.
Method 2: Change build configuration
If you click the "Switch Surface" button in the top left and go to "Build Configurations" you should see two configurations created for you by default (if you created the project through Builder). Builder defaults to your JSON file which builds Flatpaks.
Click the "Default" configuration, then click "Make Active" under "Overview". Then you can build the app as normal (e.g. with the omnibar at the top). Once it says "Build succeeded" the binary has been built.
But where? Look for the path listed in the "Overview" for the "Default" configuration -- under "Install Prefix". This will be something like "/home/user/.cache/gnome-builder/install/AppName/host"
In there is a "bin" directory with your app.
Method 3 (Preferred): Build using ninja
From the Editor surface, press CTRL+SHIFT+ALT+T to open a terminal inside Builder, which defaults to your $BUILDDIR
In the terminal that's open, simply type "ninja". If it says "ninja: no work to do." your app is already built and up to date. You can type "ninja clean" and then "ninja" if you want to do a fresh rebuild.
Inside this directory, (something like "~/.cache/gnome-builder/projects/AppName/builds/default-host-unversioned") there will be a "src" directory which is where the app is built.
Running your app
You may not be able to double click this from a file manager, so open the directory in a terminal and type "./appname" to run the app.
In addition to wappa's answer, for GNOME Builder 43, the file system is ~/.var/app/org.gnome.Builder/cache/gnome-builder/projects/<your-project-name>. The default build directory is builds/<your-application-id>.json-flatpak-org.gnome.Platform-43-x86_64-main under the file system; you can find object files, executable files, Meson and Ninja files including build.ninja, etc. here.
Besides, you can find the output Flatpak files at flatpak/staging/x86_64-main under the file system. To export a Flatpak bundle, you can click the down arrow on the top bar and click "export". The exported Flatpak bundle is at this directory. The executable binary file is under files/bin. You can also find application data, icons, font configurations, etc., under the files directory.
To configure the location, you can still click the down arrow on the top bar and click "Configure Project...". On the "Overview" page, you can view which configuration you are using currently, corresponding to the configuration options on the sidebar: "Default" (~/.var/app/org.gnome.Builder/cache/gnome-builder/install/<your-project-name>/host) and <your-application-id>.json. By default, the latter one is selected, whose installation prefix is /app. If you look at the Build Output, you can observe that the desktop file, source files, GSchema XML, AppData XML, Icons, etc., are installed into /app. The /app is the path in Flatpak's sandbox filesystem rather than the path in the main filesystem of your Linux OS.
If you want to avoid using Flatpak, you can go to the build directory and manually build by Meson and Ninja.

What is the reason for nodemon working in cmd but not in a batch file?

I am in the process of making a discord bot. All of the code that I have written for the bot works except for the batch file that is supposed to run it. Originally I was just using the node command and when I opened cmd, navigated to the folder, and typed it manually it worked fine, but when I put that same code into a batch file it gave me this error:
'node' is not recognized as an internal or external command, operable program or batch file.
This is all the code for that batch file:
#echo off
node bot.js
pause
The node command was in my path so I'm not sure why it wasn't working, but in another post, someone recommended that instead of typing just node to type the full file path, so I tried this and it worked.
Here is the new working code:
#echo off
"C:\Program Files\nodejs\node.exe" bot.js
pause
Then I installed nodemon. Again this works in the cmd when I navigated to the folder and typed it manually, but when I try to do it in the batch file it does not work. Instead of giving me the error it had been before the window just instantly closes. Here is that code:
#echo off
nodemon bot.js
pause
Since I have the pause command at the end of the code it should stop there if I get an error, but it is closing before it gets there for some reason. The nodemon command is in my path and I have also tried replacing nodemon with the file path, C:\Users\tdkni\AppData\Roaming\npm\nodemon.cmd, like I was recommended in the previous post. Neither of these solutions worked, and I think that is because there is some other problem besides the nodemon command not being detected. I don't see any error message since it is closing instantly so I don't know exactly what is wrong.
The registration of the file extensions .bat and .cmd is as follows according to an advice in a comment deleted in the meantime.
Well, it is pretty clear why node.exe was not found by cmd.exe in directory C:\Program Files\nodejs.
Local Path being system and user Path concatenated contains "C:\Program Files\nodejs;" instead of just C:\Program Files\nodejs.
Folder paths in Path should be never enclosed in double quotes with one exception: The folder path itself contains one or more ;. In this case the folder path with ; must be enclosed in double quotes to get the semicolon(s) in folder path not interpreted as separator between the folder paths. That is general CSV syntax as described on Wikipedia article comma-separated values which is used by Windows for the folder paths in Path with using semicolon as separator.
For that reason cmd.exe searches in a folder with name C:\Program Files\nodejs; for node.* with a file extension listed semicolon separated in environment variable PATHEXT. But there is no folder C:\Program Files\nodejs; because the folder is C:\Program Files\nodejs without the semicolon at end.
And also PATHEXT is defined wrong as it contains at end the folder path C:\Program Files\nodejs although it should contain only file extensions separated by a semicolon.
Other small mistakes:
The first 4 folder paths in system PATH should be always:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0
Some installers add folder paths at beginning of folder paths list instead of appending them at end as it can be seen here. The Intel64 compiler and the Oracle Java folder paths should be moved in system PATH after PowerShell folder path.
Folder paths can but should not end with a backslash. All backslashes at end of a folder path should be removed from system and user PATH. Microsoft added since Windows Vista the PowerShell path with a trailing backslash for some unknown reason. But it is safe and recommended to nevertheless remove the backslash after WindowsPowerShell\v1.0.
System and user Path (if latter is existing at all) and also PATHEXT should not end with a semicolon. There should be no ; after last folder path respectively last file extension as this means according to CSV specification that there is one more value (folder path, file extension) which is an empty value.
I recommend to define system Path with following value respectively folder paths:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0;%SystemRoot%\System32\OpenSSH;%ProgramFiles(x86)%\Common Files\Intel\Shared Libraries\redist\intel64\compiler;%ProgramFiles(x86)%\Common Files\Oracle\Java\javapath;%ProgramFiles%\nodejs;%ProgramFiles(x86)%\Windows Kits\8.1\Windows Performance Toolkit
I recommend to define user Path with following value respectively folder paths:
%LocalAppData%\Microsoft\WindowsApps;%AppData%\npm
Those two folder paths are user account related and should be added for that reason to user and not system Path.
I recommend to fix system environment variable PATHEXT to:
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
For more details about usage of Path and PATHEXT see the answer on What is the reason for '...' is not recognized as an internal or external command, operable program or batch file? Please take also a look on Wikipedia article about Windows Environment Variables.
Here's my answer to the original question, for the benefit of other Windows users (Linux/Mac users not my problem).
In essence, user is trying to run some script.js file with nodemon;
C:\path\to\my\project>nodemon bot.js
, and wants to put in a batch file.
If nodemon is installed globally -g, it installs under
C:\Users\<YourLogin>\AppData\Roaming\npm\nodemon.cmd
So your batch file should be
cd C:\path\to\my\project\
%AppData%\npm\nodemon.cmd bot.js
PAUSE press any key to exit
I'd like to thank all of you for trying to help me with this problem I was having. You have all been very helpful, and while it may not have fixed my problem it did help me understand how all of this works. I just tried to start the bot using the batch file I made and it suddenly worked. I don't know why because I tried to start it the same way I had been the entire time, but as far as I could find, no one else was having this issue anyways so it probably won't matter much that I don't know what fixed it. Again, thank you to everyone that helped me with this.
Give this a try for us please, if it works, I will explain:
#echo off
cd /d "C:\Users\tdkni\AppData\Roaming\npm"
echo Testing Script > OUTPUT.log
nodemon.cmd bot.js >> OUTPUT.log
pause
I know this thread is older but I faced the same issue today. If someone like me stumbled across, based on joedotnot's answer, here is what it fixed for me.
devserver.cmd
#echo off
echo Auto Starting Development Server
cmd /k "cd x:\cmdproxy & config\env.cmd & %AppData%\npm\nodemon.cmd"
Where X: is the development folder on the VM Host System mapped as Network Drive in the development Guest System. And config\env.cmd is another batch file which holds some env settings.
My server file is named index.js so there was no need to add is as argument. Nodemon finds the file automatically.

How do I open GitKraken after installation on Windows 10?

It seems that this is a real issue. In How to Install GitKraken, they point to a %APPDATA%/.gitkraken folder. Once there, you have "profiles" and "service" folders and "config", "log" and "secFile" files. Inside those folders, there are no signs of an executable. It's not under Program Files, nor in the PATH environment variable, it's nowhere to be found. If you install it again, it opens normally and logged in your profile, but after closing it, there's no way to open it again. There are no shortcuts.
What am I missing?
By default GitKraken is installed to your local app data folder. You can find the executable file inside %LOCALAPPDATA%\gitkraken\app-<app-version>
As of this writing, the latest version is 2.0.1 so the exe will be %LOCALAPPDATA%\gitkraken\app-2.0.1\gitkraken.exe
And easier way to open the software would be using the shortcut in the start menu:

Resources