Access underscore.js from client after using npm in node.js
In Node.js, I installed the
underscore.js module. Tried to include it in the layout like this:
But socket.io is the only one that was found. In
node_modules/socket.io, there is no socket.io.js file, but in
node_modules/underscore/, there is a udnerscore-min.js. How exactly am I pulling down socket.io but not underscore.js? Does socket.io run some code and create the socket.io/ directory and put the file there? If so, what method is underscore.js using?
I assume your using the express framework with something like:
var app = express.createServer(), io = io.listen(app);
If that is the case then Socket.io will automatically create a route for /socket.io/socket.io.js. If you want to server underscore-min.js you could try symlinking it to a static directory (which is a bit hacky...).
I guess using something like Stitch or minifying all your external libraries to one file would be a better solution and it would also reduce the amount of HTTP requests...
I just discovered visionmedia/asset which is really amazing! It still doesn't provide access to your modules inside
You've got an app using express.js? Let's say you want to provider the brwowser with Jquery and underscore. All You have to now is:
$ asset jquery underscore -c -o public/js install : [email protected] install : [email protected] download : [email protected] complete : [email protected] public/js/jquery.min.js download : [email protected] complete : [email protected] public/js/underscore.min.js
And that's it! :-)