When you add some underscore functions to your meteor app, you can't test it in browser console. So we need test it somewhere else.
-
Create a new folder as the test project root;
-
Install underscore package locally, which means the package is specific for this project;
-
Create a node script to test the underscore functions.
The whole work flow is like this:
$ mkdir myapp
$ cd myapp
$ npm install underscore
$ cat << EOF > myfunc.js
var _ = require('underscore');
var res = _.map([1, 2, 3], function(num){ return num * 3; });
console.log(res);
EOF
$ node myfunc
[ 3, 6, 9 ]
You can't use var _ = require('underscore');
in node REPL shell, for node shell use "_" to hold the last result.
Note:
-
See Why can't npm just put everything in one place, like other package managers? on npm's FAQ for the reason why npm not install pakcage globally like pip.
-
For node, how to determine install a package locally or globally? According to npm 1.0: Global vs Local installation
i. If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
i. If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable. For example, install bower with
npm install bower -g
.