问题
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.
回答1:
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.
回答2:
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.
回答3:
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 :)
回答4:
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
回答5:
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.
回答6:
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"
回答7:
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.
回答8:
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
回答9:
For MAC Users, try this (run the following on your terminal)
export PATH="/Users/username/.npm-packages/bin:$PATH"
来源:https://stackoverflow.com/questions/22107706/sails-js-path-variable-sails-command-not-recognized