How to tersely run a globally installed Node.js app - node.js

I was recently using mongo-express which is written in Node.js. I've installed it globally following instructions on their GitHub page. It says in order to run it:
cd YOUR_PATH/node_modules/mongo-express/ && node app.js
I was wondering if there's any workarounds to avoid changing directory to the app's folder first (using cd).
By the way, in npm's doc, it says
When in global mode, executables are linked into {prefix}/bin on Unix.
In my case (using mac), executable app.js is linked into /usr/local/bin. But if I just type app.js in the command line trying to run it, it'd say -bash: /usr/local/bin/app.js: Permission denied. Even if this works, wouldn't app.js be a too generic name and become conflicted with other apps later?
Thanks for helping.

Related

how to run mbpipe... a program I just installed

I'm trying to use this tool: https://github.com/mapbox/node-mbtiles/wiki/Post-processing-MBTiles-with-MBPipe
I've installed mbtiles with npm install -g mbtiles. I've also installed it locally (in the dir I'm working in) with just plain npm install mbtiles.
That part worked (I was able to download the files), but now according to the readme I can just start entering in commands like
mbpipe 'pngquant 64' myMbTilesFile.mbtiles and it's supposed to work?
Umm... don't I have to run a specific script file (like "node scriptfile.js")? This is acting like I can call functions within a script and pass it variables? I can tell you, as the user mentioned, that 'mbpipe' is within the utils.js file I have.... but how am I supposed to use it?
when I enter in the above command, I of course get "mbpipe: command not found"
So... what are they talking about?

NodeJS installation to jenkins : npm not found

Maybe someone can tell me what I missed installing nodeJS to jenkins, because when I want to execute shell script npm update I get error npm: not found.
I installed jenkins nodejs plugin then added installer:
After I created job with prams:
What I need to do more, to have accessible npm in any jenkins job?
It works for me. The only difference is that where you have a text box that reads "0.12.7", I have a popup menu that reads "Node.js 0.12.7". Maybe something has gone wrong and you should delete the installer and add it back?
Windows users, did you restart?
Do keep in mind that you need to restart active processes after installing npm.
During installation the folder of your npm.cmd is added to the PATH variable. However, active applications don't refresh their PATH variable automatically. That also holds for your active Jenkins service (and its child processes). They are still running with an old version of your PATH variable.
In other words, you need to restart the Jenkins service (or restart your entire system). Once restarted, Jenkins will have an updated PATH variable, and it will be able to find the npm.cmd processes and others.
What's wrong with using absolute paths?
Using the full path is not a solid solution. A package.json file can contain references to other cli processes (e.g. node, ng, react-scripts, npm-run-all, ...). You will probably have similar issues there. There is no way to keep up and reference all of them with full paths.

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

Sails.js - PATH variable - sails command not recognized

After I npm installed Sails.js on Windows Server 2008, "sails" command is not recognized.
Can someone give me a hint on what values to use in the PATH variable? As I understand it is Node.exe that runs the sails.js file. But if I try tunning "node sails.js" command in cmd, it recognizes it, but can't find some of the dependencies.
On my Windows 7 machine everything installed and is running like a charm.
I ended up writing a batch file and putting it into system32 folder "c:\Windows\System32\sails.bat" with this one line:
node C:\Users\XXXXXXXX\AppData\Roaming\npm\node_modules\sails\bin\sails.js
Now, sails lift works well.
Did you try using the -g (for global) option?
If I use:
npm install -g sails
On either Windows 8.1 or Server 2012R2, I find it is accessible from the path just fine.
Install sails globally
npm install -g sails
If you have right to add Environment variables (Start => Computer=> Properties=>Advance system setting => Advance(Tab)=>Environment Variable(button at the bottom) => User variable for ...(the top one) => find "PATH" => edit ) and add the location of your npm folder (C:\Users\XXXXXX\AppData\Roaming\npm) (this folder can be hidden so enable show hidden folder to locate your path)
open new cmd window and enjoy sails :)
it looks line a sails.cmd file is create in the global npm folder, so if you add this folder C:\Users\XXXXXX\AppData\Roaming\npm to your PATH sails will be a recognized command, and will accept all valid parameters (tried new and lift and both look OK).
In this way all other node packaged that are command line based should work, if they follow this convention to install on Windows (I think this is the case).
I don't have a Windows Server 2008 to test on but it seems it fails to do this process automatically, as it does on Windows 7
If you add a .bat file in system32, remember to add parameters to the bat script. Found that out after trying some of the solutions previously posted here. My example:
C:\Users\Anton\AppData\Roaming\npm\sails %1 %2
Sails is not a directory there, it's a file. Hope this helps someone.
For ubuntu 16.+
Get prefix of node
npm get prefix
look loke this : '/home/ubuntu/node'
now open bash_profile
sudo vim ~/.profile
Add this line if you already have path in this file
export PATH="$PATH:/home/ubuntu/node/bin"
if you node prefix is diff replace with your prefix
export PATH="$PATH:{ your-node-prefix }/bin"
you can add new 'node' commands like 'npm', using batch scripting.
Create a sails.cmd file in your desktop. (new text file -> rename to
'sails.cmd').
Right-click on sails.cmd and select Edit.
Copy and paste this code into your sails.cmd:
#ECHO OFF
SET arguments=%1 %2 %3 %4 %5 %6 %7 %8 %9
node %APPDATA%\npm\node_modules\sails\bin\sails.js %arguments%
Save and copy your sails.cmd into your Node.js installation
directory, for example: C:\Program Files\nodejs
And now everything with sails.js on windows are very simple. Just run this command in your terminal:
sails or sails -v or whatever you want with sails! ;)
Enjoy!
UPDATE!
At this time I highly recommend using the WizofOz solution. It is the most correct way to proceed in a node.js environment.
To help clarify for Windows 8 users. After installing sails globally if receiving errors do this:
Create a sails.txt file
Add this
node C:\Users\XXXXXXX\npm\node_modules\sails\bin\sails.js new
node C:\Users\XXXXXXX\npm\node_modules\sails\bin\sails.js lift
Now re-save it as sails.bat
Add this new file to your C:\Windows\System32
Navigate to the folder you want to hold your new sails app. Scaffold the app with the following command:
sails new
If you don't want a front-end, instead type:
sails new --no-frontend
We can also launch the app using the lift command:
sails lift
This will launch our new app on port 1337
For MAC Users, try this (run the following on your terminal)
export PATH="/Users/username/.npm-packages/bin:$PATH"

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