I'm playing around with io.js and in doing so have found myself switching between Node and io.js a lot.
In fact; I was missing some kind of warning or error when I install a package that specifically requires io.js for example. Here's a simple package.json that serves as an example:
{
"name": "myApp",
"version": "1.0.0",
"description": "Simple demo site",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.1.0"
},
"engineStrict" : "true",
"engines" :{
"iojs" : "1.6.3"
}
}
The app.js is trivial, but just for completion:
var app = module.exports = require('express')();
app.get('/user', function(req, res){
res.send(200, { name: 'tobi' });
});
app.listen(3000);
console.log("Application is listening on http://localhost:3000/user")
If I'm using node 0.12.0 in my terminal nvm use node
for example and then cleaning our the node_modules
(rm -rf node_modules
), I can still npm install
the packages. No problem, no warning, no error. It might not run but it installs all the dependencies.
However, I found in the documentation that if I step up one directory cd ..
and then remove the node_modules
(rm -rf node_modules
) again and run
npm install myApp
(where myApp is the folder with my package.json in). I get the warning. Or error if I have set the "engineStrict": "true"
.
Now, finally to my question; what if I switch over to io.js (nvm use iojs
), and then run:
npm install myApp
No warning or error. Great - it installs just fine. But ... there's no node_modules
in the myApp
-folder.
The first line of feedback from npm install
states this:
demoapp@1.0.0 ../../../../../../../node_modules/myApp
The ../../../../../../../
is the root of my user (~
). And the myApp is there and works. But why?
And also: is there another way to get the installation error than to 1) step up one directory, 2) npm install [directory name] 3) look in the root for what got installed?
Thank you for any help on this.
[UPDATE] In the words in Homer
Doh!
I just found another question and answer about this. Leaving it here for reference and as a testament of my own lack of RTM.
There's a --prefix-flag that you can use to the directory where you want to install the package. The full command, from my example above, would be:
npm install --prefix ./myApp/ myApp
But.... that doesn't give me the warning... Now do I really have to choose between getting the warning and decide where to install the package?