How to install Node.js with Windows PowerShell PackageManager (OneGet)? - node.js

I tried Install-Package nodejs, which seems to have done something:
PS C:\WINDOWS\system32> Install-Package nodejs
The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'chocolatey'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y
Name Version Source Summary
---- ------- ------ -------
nodejs.install 11.10.0 chocolatey Node JS - Evented I/O for v8 JavaScript.
nodejs 11.10.0 chocolatey Node JS - Evented I/O for v8 JavaScript.
Then when I try to run the node command, it fails:
PS C:\WINDOWS\system32> node
node : The term 'node' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ node
+ ~~~~
+ CategoryInfo : ObjectNotFound: (node:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
How do I do it properly with PackageManager, so that the command is then available?
Not sure if this other question is related: Chocolaty packages not installing via OneGet/PackageManagement in Windows 10?
As that other question suggests, I tried setting Set-ExecutionPolicy Unrestricted, the uninstalling and reinstalling nodejs, but the result is the same.
I do see that after install the following files exist:
C:\Chocolatey\lib\nodejs.11.10.0\nodejs.11.10.0.nupkg
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\legal\LICENSE.txt
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\legal\VERIFICATION.txt
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\tools\chocolateyInstall.ps1
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\tools\node-v11.10.0-x64.msi
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\tools\node-v11.10.0-x86.msi
which makes me think that maybe it expects me to run the installer manually after?
My goal is to simply install anything I need on a new Windows machine from a script, without having to download/install them all manually with GUIs.

I was able to reproduce this, but also was able to resolve it. The issue is that the node executable isn't on the PATH after installing with Install-Package. However, this does make some sense as the current PowerShell process won't pick up outside changes to environment variables until it is relaunched.
Chocolatey's refreshenv command works sometimes but not always, and after installing nodejs with Install-Package, refreshenv did not work to refresh the PATH variable. What did work was launching a new PowerShell session and running the node command, which ran the executable successfully:
> node
Welcome to Node.js v16.7.0.
Type ".help" for more information.
>
choco.exe can sometimes mask this but usually Chocolatey won't generate shims for executables placed by EXE or MSI installers (unless the package maintainer forcibly creates them).
Tip: In case you are in a situation where you need to call the binary from the same process that installed the package (e.g. during a chef-client run where refreshenv isn't an option), use the fully-qualified path to the executable to invoke the newly-installed software.
Additionally, don't use the Chocolatey OneGet provider in real automation; it's not yet stable and looks like it hasn't seen any development activity in five years at this time of writing. From the README.md:
NOTE: Seeking maintainers to help finish this Provider. Please inquire on the issues list or on Gitter (see the chat room below). Thanks!
There is an alternative listed in the same README:
NOTE: For now, you may be more interested in using the ChocolateyGet provider as a stop gap solution until this provider is ready. See https://github.com/jianyunt/ChocolateyGet for details
I tried this and it seems to work, but I would still recommend using the official choco.exe binary. It's easy to install and you'll get the best support when using it. It's also telling that configuration management solutions (such as Chef's chocolatey_package resource) continue to make use of the binaries and will generally list installing the client as a prerequisite, even though technically the PackageManagement module could be used as a native solution instead.

It worked for me:
winget install nodejs

Related

How to run NodeJS CLI tools without having to type npx

TL;DR
I cannot execute commands such as tsc unless I include npx before it (e.g npx tsc). How can I fix this?
The title is a bad explanation of the problem I have.
Say I have installed an npm package with a CLI with it (typescript in this example). And the CLI is used like
tsc <filename> or just tsc. But whenever I try to do it like that, I get an error like
'tsc' is not recognized as an internal or external command,
operable program or batch file.
But... when I do
npx tsc
then it works!
So whats the problem?
The problem with doing npx tsc is because
npx is slow at executing commands
its annoying having to type npx and the front of every command.
And the thing is, this was originally not a problem with WSL.
Why dont you just use WSL?
I have always had problems with WSL (primarily permission issues due to security reasons) and so I uninstalled WSL and just used command prompt. I would have perferred using WSL but it was simply not an option.
Other Info:
I am using Windows command prompt.
I have installed the packages globally
So is there a way to just execute commands that way or is it Command prompts fault?
! this only works for Windows !
Ok, so I came across this post and thankfully, the first answer there was the solution!
Just add %USERPROFILE%\AppData\Roaming\npm to the path variable in system variables!
To access the system variables, press the Windows key, type Environment variables and click on Environment variables at the bottom of the window. The path variable can be found under User variables for (profile name).

Node.js - "node" command works, but not when through another framework

I have Node.js + NPM installed; I can run node -v in my console and get back the current version.
I have also tried using NVM Windows as a Node.js version manager and can run both node -v and npm -v there as well.
HOWEVER, when trying to use another framework like Gulp or Ionic or whatever, I keep getting the error:
'node' is not recognized as an internal or external command,
operable program or batch file.
node is obviously a cmdlet as I can run node -v.. but somehow my other frameworks are no longer able to find it.
Path is correct and everything looks good.
What am I missing here?
The program ConEmu for windows terminal management wasn't pulling or allowing programs to access the paths through subcalls or something it seems. I tested with CMD and Powershell respectively and both worked as expected.
I couldn't get ConEmu to seemingly pass these path to subroutines.. so I uninstalled it and found an alternative called Cmder that is built on ConEmu and it was able to pick them up just fine.
I don't know specifically if it was just a setting in ConEmu I couldn't find or if I needed to manually add these--but happy knowing Cmder just does it automatically.

Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine

I'm new to Play framework. Please explain the meaning of the below warning.
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript assets compilation, which in some cases may be orders of magnitude slower than using node.js
I don't want anything that slow down my application so please advice if I should change the JS Engine to Node.js, but my PlayFramework project is using Java on the server side.
You need to install Node.js and then tell the sbt/java engine to use it.
brew install node
Edit .bash_profile and add:
export SBT_OPTS="${SBT_OPTS} -Dsbt.jse.engineType=Node -Dsbt.jse.command=$(which node)"
This eliminated the warning for me on OSX
In Windows:
Install node.js
Go to Control Panel - System and Security - System - Advanced system settings
Click Environment Variables...
Search in System variables for SBT_OPTS
If such exists, click Edit... and concatenate -Dsbt.jse.engineType=Node to Variable value
If such does NOT exist, click New... and write SBT_OPTS to Variable name and -Dsbt.jse.engineType=Node to Variable value
Click OK - OK - OK
Restart any command prompt (cmd, PowerShell) that is currently running Play Framework
in ubuntu
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
then add as above to your .profile in your home directory
export SBT_OPTS="${SBT_OPTS} -Dsbt.jse.engineType=Node -Dsbt.jse.command=$(which node)"
then
. ./.profile
to reload your .profile
For a more flexible install using node version manager check the following tutorial:
how to install node js on an ubuntu 14.04 server
Build again and the warning about using the Trireme stuff should be gone.
As an alternative to setting the environment variable, you can add this line to your build.sbt file:
JsEngineKeys.engineType := JsEngineKeys.EngineType.Node
See: https://github.com/sbt/sbt-js-engine
sbt plugins requiring a JS engine are used only in the build process, and so missing Node.js only slows down assets building stages if you use any.
The built application is not affected.
Anyway, you may want to install node.js to your PATH, where it should be auto-detected.
in Windows 10:
Install node.js from https://nodejs.org/en/
(The installer automatically adds node.js to your PATH)
then add:
export SBT_OPTS="$SBT_OPTS -Dsbt.jse.engineType=Node"
to your plugins.sbt in
. ./project/plugins.sbt
Worked for me - the warning has disappeared!
EDIT:
Apparently plugins.sbt was the wrong place to add the
export SBT_OPTS="$SBT_OPTS -Dsbt.jse.engineType=Node"
...although the warning disappeared when loading my app, it led to an error when relaunching the app a couple of hours later:
error: not found: value export
I would be glad if anyone could help and tell me where to put the export.

Nodejs is not available outside of its installation directory

I installed nodejs 64bit on my windows8.
NOTE: By install, I mean I used node-v0.10.35-x64.msi andn its Windows8 for SurfacePro3.
I am not familiar with add PATH. What exactly should add I add and how I run it after I added it?
However, nodejs will not be available outside of its own installation folder.
For example,
if I installed it at /www/test directory, then it will not available either in www or any level after test, like, /www/test/anothertest. Only /www/test will have node running.
I test it by write node -v on /www/test directory in command prompt. I consider its available when it returns me the node version number. When it is not recognized, it will say 'node' is not recognized as an internal or external command...'
I insta
Restart your computer always fix everything....
Yes it did now everything works lol

Running Azure node.js Tools on Ubuntu

I have followed these instructions.
And as far as I can tell I have successfully installed node.js azure tools. No error - nothing to suggest it failed.
However, I cannot, and the documentation says, simple run "azure"...
Maybe there is something I am missing with node.js?
There are a few problems you may be experiencing.
First of all, I would ensure you are running Node.js v0.6.20. You can do this by opening the command prompt and running:
node -v
You should have v0.6.20 echoed back.
If this doesn't work, you may be missing a path variable to Node.js or the NPM cache. Verify the Environment variables exist by running [in the command prompt]:
path
you should see two paths:
%appdata%\npm
[x64 Machine]
%programfiles(x86)%\nodejs\
[x86 Machine]
%programfiles%\nodejs\
If this doesn't work, I would check to ensure that the azure module was loaded into the %appdata%\npm\node_modules directory.
It could be the PATH issue. In my case, the azure program is located at ~/.npm-global/bin.
run "export PATH=$PATH:~/.npm-global/bin". Or just add to bash source file

Resources