CasperJS from Cygwin - cygwin

I've just installed node.js, python, casperjs and slimerjs. Not sure if relevant, but I initially used:
npm install capserjs
and
npm install slimerjs
(without the -g flag)
I've since uninstalled both and reinstalled using -g.
When I type "casperjs" from the Windows command prompt, it appears to work fine. However, I prefer to use Cygwin. Typing in "casperjs" from Cygwin yields the following message:
Can't open '/cygdrive/c/[pwd path]/C:\Users[my user]\AppData\Roaming\npm/node_modules/casperjs/bin/bootstrap.js'
...where [pwd path] is whatever directory I happen to be in at the time, and [my user] is my Windows username.
The above suggests it's trying to use $AppData as the root of the path, but for some reason it's also appending the present working directory. When I installed these on another laptop before I tried this one, I didn't experience this problem.
Does anyone know why this might be happening?

Related

Node and npm not found after restarting macOS

I am using my corporate's laptop and am a new mac User (used Ubuntu before) :
OS: macOS Monterey Version 12.2
There are two accounts, administrator and mine - I don't have sudo rights. To install homebrew without administrator rights, I followed this Installation.
To install the node - I used brew install node. Both node -v and npm -v were working. When I restarted the laptop, I cannot find node/npm.
On running $ node -v, I get -bash: node: command not found (I changed my default terminal from zsh to bash and the output is the same for both of them)
I tried this solution but couldn't find nvm in the system. Am new to mac and I believe nvm is some kind of package manager like homebrew so this solution is not applicable to me (correct me if I am wrong).
How can I install things in my system without sudo rights and keep them permanently(like node)?
EDIT:
(After adding brew to the PATH) On running - brew list|grep node, I got - node
$ echo $PATH gives /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/parthkapadia/homebrew/bin
EDIT2:
Adding brew to path solved the issue, now I can even access node and npm (even after restarting). I used this site to add homebrew/bin to path (in zsh terminal)
The issue was homebrew's path. It was not added to the PATH variable.
When I restarted the system, homebrew was no longer in the PATH (as it was temporarily added probably when I installed it). As homebrew was not added to PATH, the terminal didn't recognize brew or any package installed using it like node or npm.
I solved it by adding Users/username/homebrew/bin to PATH. The steps I followed are -
cd - to move to the home directory
touch .zshrc to create .zshrc file as it didn't exist
nano .zshrc to open the file for editing
Added export PATH=$PATH:/Users/yourusername/homebrew/bin in the file (this appends homebrew/bin to the PATH variable)
Now the terminal can recognize brew and hence node and npm too.
Refer this for more detailed explanation on how to add to PATH in macOS.
Thanks to all the people who helped in the comments.

Is nvm is relevant for node these days in windows, should I use it? and if yes why?

When I tried installing nvm from website -
https://github.com/coreybutler/nvm-windows
everything went good, except the nvm use, even when I execute this command this doesn't seem to do its job properly though no error is thorwn by the terminal(cmd). When I try to use
node -v
it doesn't show the version number of node, that means node is not installed. And same goes witht the
npm -v
, this too doesn't show the version number, it hasn't been finding the executable. Everything works fine, that I install nvm install too. nvm list says there it is, and it donwloads and saves it the its user/appdata/nvm folder,(I checked it). But still cmd can't find the executable. Do I manually need to set the path for the node folder that's located in the roaming/nvm/node folder.
https://github.com/coreybutler/nvm-windows/issues/221#issuecomment-262363222
This comment solved the problem with one go, I guess the key was to use powershell, now node and npm works like smoothie. ;D

BrowserSync : Command not found after installing browser-sync

There was another issue open with the same title which has been closed but my error could not be resolved using the solutions given in that issue.
Mac OSX El Capitan
Node [v5.6.0]
Npm [v3.6.0]
I installed Browser-Sync successfully using :
bash
$ sudo npm install -g browser-sync
but when I check the browser-sync version by typing :
bash
$ browser-sync --version
I get this error :
bash
-bash: browser-sync: command not found
Check where npm installs it's binaries by running npm bin -g, and then add that to your PATH.
export PATH=$PATH:/usr/local/bin
None of this was helpful to me, instead what I did was find the file location of browser sync after i executed the browser-sync download command supplied on their website. npm install -g browser-sync
Turns out my windows 10 put that downloaded file into %appdata% folder which is in Local Disk (C), but it's an invisible folder and not the correct place it should be, it needs to be in the nodejs folder inside Program Files...
So to find this folder do this: in the search bar of windows 10 type in %appdata% and press Enter, it should open up that hidden folder...
Then click on npm > npm_modules > then you should see files saying browser-sync. Highlight and drag all those files into Local Disk (C) > Program Files > nodejs. You will get allow access prompts, just allow all those.
Now browser-sync and nodejs are sitting happily together and NOW, you can go back to your CMD window and type in browser-sync --version and get the correct version.
I am taking the Coursera class titled HTMl, CSS, and Javascript for Web Developers and ran into this very problem and this solution made it possible for me to continue setting up my environment to take the class.
Although above answers are correct, there is an easy way to handle this. Instead of explicitly creating $PATH we can install Browsersync globally.
npm i -D browser-sync
Here -g option specifies npm to install browser-sync package globally and add $PATH automatically. Next check wether it is working or not by running:
browser-sync --version
Note: Even if you already installed Browsersync try running this. The issue will be resolved.

node user directory leading to command not found

I suipidly ran this script to stop having to use sudo on npm -g commands and now my node_modules are located at:
/Users/myusername/.npm-packages/lib/node_modules
when trying to run a commands i.e yo bower i get -bash: bower: command not found
Do I need to link this directory to the usr/bin?
In trying to sort this out I have run lots of commands and created symbolic links, I feel like my system is a real mess and I cannot really see what is going on? Help to ensure my system is clean would be really helpful.
Generally, it's a good idea to ensure that you do not need admin rights to run npm commands. The problem you're having, is that the directory where npm now installs its commmands (/Users/myusername/.npm-packges/bin) is not in your PATH. Your PATH is a list of directories where your shell searches for the commands you type.
You can add the directory to your path by adding the following line to the .bashrc file in your home directory (create it if it doesn't exist).
export PATH="${PATH}:/Users/myusername/.npm-packages/bin"
Open a new terminal, and bower should work again.
As an additional tip, I believe you're running on OS X? When installing Node.js using Homebrew, it is automatically installed in a proper way (no sudo needed to install packages globally and they will just work). Next time you're installing Node.js (or something else), Homebrew might be worth a try.

yeoman permission issue with nodejs and angular

I am trying to start an angular web app with yeoman but I get permission issue when trying to install the new generator. I can bypass and install generator with sudo but then I get the permission errors when running
**yo** angular
I deduce its because its trying to access npm modules that are global which the current user doesnt have permissions for, and I cant run Yo with sudo. I have done a lot of google searches and they all involve some type of hack with the NODE_PATH in the .bashrc or moving the node modules to the home directory. Has anyone found a simple solution for this issue.
Below is my problem in screenshots:
yo installs fine
when i try to install the generator without sudo complains..
install with sudo passes.
then finally when I try to run yo angular it breaks.. I believe its because yo runs as user and I have installed everything with sudo privileges. How can I get past this?
The reason it breaks, I guess, is because the whole directory tree was created as super-user.
The hacks you mentioned about using NODE_PATH and the home directory are not hacks. They exist for this same very reason. To tell node where to look for packages. And .bashrc is the place where you are supposed to change this kind shell variables.
Say you added ~/.node_modules to you NODE_PATH, then you can install all "global" in there. You could also change the permissions on /usr/local. But on linux world that is not recommended.
I also strongly recommend in not using global install with npm. Using -g and npm link is handy when developing but you shouldn't count on them. You can introduce subtle bugs in your code when you forget to add a package on you package.json but it is installed globally.
Instead of installing it globally, you can find all the packages executable on ./node_modules/.bin/ directory.
But lets say you don't want to be typing ./node_modules/.bin/yo all the time, you could create an alias on your .bashrc.
alias yo="$PWD/node_modules/.bin/yo"
and it would work like expected, and if there is no yo package installed, you get an error.

Resources