npm install -g generates the wrong script - command-line

This is a follow up this previous question related to how to install and run a javascript node.js command line tool.
According to this enter link description here you must execute npm install -g from within the folder of your project in order to be installed as a global command line tool executable from prompt.
When I run this instruction a .cmd file is created inside de global npm folder. But its content is wrong:
#"%~dp0\node_modules\lb-model-discovery\index.js" %*
I must manually change this content for it to be executed (otherwise I just get notepad being opened...) My question why npm install -g does not produced the right script in my system?

The solution is found in this github issue.
Basically the entry script (index.js) must contain this line at the top:
#!/usr/bin/env node

Related

npm not found from Visual Studio code terminal but is verified from a Command Prompt

When I try to run "npm" from VS Code terminal, I get the error "The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program."
Now, when using Command Prompt and navigated to the project folder, I verify that node.js is installed and from the command prompt I verify that npm is installed.
However, when in VSCode terminal window, neither node.js nor npm is found to be installed.
What am I missing here?
I have come across this problem before. Here is a list of potential solutions:
Make sure your terminal opens up in your project folder. Sometimes when we open our project or the terminal in visual studio, we are not directly in the right folder. Use the command cd projectName in the terminal to navigate
Did you run the npm install -g npm command in your project's terminal?
If so, use node -v and npm -v to check versions.
If not, run the command npm install -g npm in your project's terminal
Try reinstalling npm with the npm install -g npm

Npm command not recognized (ubuntu)

After installing java 8 openjdk and exporting the variable via export I ran the following command:
source /etc/enviorment
I after that when I try to run npm run tests-e2e, it says the command is not recognized.
Executing source /etc/environment has reset your shell's environment variables back to their default values, throwing away any customisations that were applied by your shell's startup scripts (/etc/profile, ~/.bash_profile and so on). In particular, it looks like you've lost the customised value of $PATH that carried the path to the directory where the npm command lives.
To recover, you can do any of:
execute exec bash -l to get a new shell that will execute the
startup scripts and therefore rebuild a properly customised $PATH variable
if you're using the GUI, close the terminal window and open a new one
log out and then log back in

ionic install fails on fsevents on Windows

I have tried to install ionic on Windows but installation has failed. What should I do?
I have tried more than 20 times but still I got the same problem.
Here I have attached the screenshot for this
Entered commands:
npm install -g cordova
npm install -g ionic
Note: this one windows server machine
My guess is that the NPM global path has not been added to your windows path.
These are the steps to try:
First verify that the command just installed can run. The output contains the full path to the command installed, just copy and paste it to the command line. In your case it might be something like this %APPDATA%\Roaming\npm\iconic -v
Lets assume that works. That means that the command was successfully installed and will run, now we need to add it to your PATH so you can run it from the command line.
Next, Press Windows key and type "path" and select "Edit environment variables for your account". From here. Add or append the path %APPDATA%\Roaming\npm to your PATH variable, and save the results.
Once it is on your PATH you can run it from any command shell window.
Next, start a new command shell (e.g., Windows+R, cmd, Enter) and then type the command iconic -v. Viola, it should work without requiring the full path to the script.
I'm doing most of this from memory so hopefully it's correct. But if it needs some tweeks, let me know and I'll update the answer.
For completness, this install didn't actually fail. The lines with fsevents are warnings. The fsevents package is only designed to work on Mac Unix so these warnings can be safely ignored.
As Suraj Rao mentioned, also see Nodejs cannot find installed module on Windows?.

Creating new file with Node.js and Express

I'm trying to learn how to use Node.js and its packages. I'm in my Command Prompt (I'm on Windows), changed directory to my project folder. Then I installed the Express package:
npm install express --save
The npm installed the Express package. Now, while I'm still in the directory, I'm trying to create a new file:
touch index.js
But the file isn't created and I'm getting the following message:
'touch' is not recognized as an internal or external command, operable program or batch file.
Why is that? What am I doing wrong?
touch is no Windows command.
In this answer, they suggest this as an equivalent:
echo $null >> filename
touch is a Unix command that creates an empty file (or updates its timestamp if it doesn't exist). It has nothing to do with Node specifically.
Most Unix distributions (including OSX) will have touch installed by default. So I suspect you're on a Windows machine....

Chmod u+x windows cmd

I'm trying to install Scalatra on windows seven and need to change a file to executable...the Scalatra documentation says to do this, which is unix. What is the windows equivalant?
chmod u+x srt
You can simply open the relevant folder with a unix command prompt (I use git bash) and execute the unix commands from there
To get scalatra-sbt going on Windows, either port you own sbt.bat from scalatra-sbt, or install chmod via cygwin.
Assuming you've successfully installed the rest of Conscript and giter8, you can start a project that downloads scalatra-sbt. From there, one can look through the ./sbt source, and port the bash script functionality to your own windows specific script, or install a unix compatibility layer into Windows. If you go down the "windows specific script" route, perhaps the scalatra-sbt would appreciate the project contribution.
The "unix compatibility layer" route will eventually allow you to run ./sbt. chmod is a unix command line function, and is provided in a default package of the tool set cygwin, which provides a complete lunix-like environment. Once inside a cygwin terminal, you can chmod your file, as mentioned in the scalatra-sbt first project.
Diving into the contents of ./sbt from scalatra-sbt, this is actually unix script wrapper around the scala build tool (also referred to, confusingly, as sbt). If while trying to run ./sbt you get strange '\r' errors, install the cygwin package dos2unix, and then run it on the sbt file. If you run into any "which: no curl in..." or "which: no wget in..." errors, go back to the cygwin installer, find those packages such as wget, and then install those programs.
By the way, the last thing the scalatra-sbt script runs is the Scala build tool. The Scala build tool sbt itself has many reported issues with cygwin's default configuration, so you will likely need to do more research. Depending on what issues you're running into on your specific setup, you may need to make changes to the end of the ./sbt script to adjust the parameters used to launch the Scala build tool.