npm installs not available in CasperJS - node.js

According to the CasperJS Documentation, I should just be able to install things through npm and then require them in my CasperJS scripts for use (since 1.1 apparently, and I'm using 1.1.0-beta3)
However, this doesn't work for me and I get the error "CasperError: Can't find module ModuleName", where I've tried read, underscore, readline, etc. And, they've all been installed using sudo npm install ModuleName.
Is there something I'm missing?
EDIT: For reference, this is related, but not identical, to my question here.

Related

Installing a node module from a gobally installed version

I have an interesting question. let us say that I'm going on a holiday where I don't have access to the internet. I happen to bring my laptop with me so that I can write some code. Me being an idiot or smart depending on perspective, I usually install my node modules using the global flag. I suspect that this adds the module locally.
My Question.
Is it possible to npm install a module locally installed into a new project without having access to the internet?
if so, what command does one run?
This is another way.
You will need to use the npm install command with the --offline flag, like this:
npm install --offline \<nameOfModule>

How to use NPM programmatically?

After seeing this post and other resources, I wanted to try using NPM programmatically so simply I tried:
const npm = require('npm');
but I run into an error of Error: Cannot find module 'npm'.
I did some research and all I saw was to try running npm install npm#latest -g which just updates NPM if I'm not mistaken but I ran it anyways and no change. NPM is already installed globally and I did try installing it locally which got rid of the error but broke the rest of my project so I assume there's a reason that wasn't recommended.
All of the posts I've seen have been older so is this not supported anymore? All the documentation I can find is about the cli and not using it as a module.
Use
$ npm i npm
without the global -g Flag
Note: The NPM API is not intended for external use (even tho it is somewhat documented). The problem is, the NPM API does not guarantee stability. In fact, it doesn't even follow semantic versioning. An update to the NPM API is likely to break your script if you heavily rely on it.
If you want to use NPM externally, it would be better to use it as it is right now: a command-line program.

npm path and installation issues - suggestions

I have used to install my nodejs on D:\ drive instead of C and have set environment variables to D drive node & npm folders.
Then i changed npm installation path as "prefix=D:\node\node_modules\npm
" on "npmrc" file. So i could confirm that all user based modules are pointing on D drive npm folder instead of appdata.
I tried to install express js globally and i used to check the package tree on my cli as mentioned below,
npm ll -g
while trying this command am getting npm extraneous ERR,
Please suggest me that which way i have to use npm path and installation stuffs.
Thanks in advance.
It might seem like a good idea to install packages globally, but this is one great reason not to.
Often used packages like express, and cookies should be kept local to a package. Mostly because of versioning issues. You might have one package using express2, but your new one wants to use express3. You would have trouble if it was a global install. When in doubt leave off that -g, and use a --save instead. (This adds the package to your npm dependencies list.)
On the other hand, command line tools like mocha, yeoman, and uh not much else that I know of should be installed with the -g flag.
I'm not much of a windows person, so you'll have to look a little yourself, but I would also recommend not installing Node by hand, but instead using a version manager like nvm to do that stuff. Here's an nvm port for windows: https://github.com/coreybutler/nvm-windows

Unable to use NPM without sudo

I have just installed node and NPM using homebrew, and before that with the package downloaded from the Nodejs website and I still cannot use npm at all without prefixing it with sudo.
When I try npm -v for example, no error is shown, my terminal just waits and waits and waits until finally, a [Process completed] message appears. Why is this and how do I fix it?
I have searched around and tried many things, including the advice in this SO post
Have you added your homebrew location to "$PATH" by adding "export PATH="/usr/local/bin:$PATH" to your bash profile?
The simplest solution I found to make it work for me is to use nvm instead.
https://github.com/creationix/nvm
You probably don't need, or want the feature given by nvm (Switching between Node.js versions) but it is meant to be use in user land and doesn't require access to /usr/lib or the like.
And therefore will provide you what you need without any weird hack.
With Aurelien Thierot's help, I figured out what the issue was: my dotfiles had an npm() function that I created to ease installation of npm packages, this had overridden npm itself.
For those that are interested, my fixed npm function for installing packages is:
function npmi() {
npm install --save-dev "$#"
}

Additional installation steps with npm install

I can't find this documented anywhere, but I'm working on a node package that will be installed via npm install -g. This includes a binary and also several other sub packages that will be yeoman generators. As far as I can tell, these also have to be installed via npm install -g (or npm link). There doesn't seem to be any other way to use a generator. If there is, it would be fine to point yeoman to one of the generators relative to this project too.
When my package is installed, I want all of the generators to be installed as well since my script will ultimately end up calling yo one-of-my-generators.
Is there anything I can do to make npm install of my project also install/link all of the generators it contains in one step?
add them as peerDependencies in your package.json file. See the blog at http://blog.nodejs.org/2013/02/07/peer-dependencies/
Its also how we install things like mocha

Resources