Question

I want to add Underscore JS to be used in the BackEnd so I can call _. functions from my Controllers. How do I do that?

Was it helpful?

Solution 2

First, you have to install the library you want to add with npm install --save <libraryName>.

Then, on top of your controller, before module.exports = ..., require this library:

var libraryName = require('<libraryName>');

That's it.

In case of Underscore.js it will be:

npm install --save underscore

then

var _ = require('underscore');

on top of your controller. After that you'll be able to use _.-functions anywhere in this file.

UPDATE

The answer by InternalFX makes perfect sense too. Sails.js indeed globalizes Lodash via _, and pretty much all the functionality of Underscore Lodash implements too, so in this case, that's right, you don't even have to do anything.

OTHER TIPS

You don't need to do anything.

Sails loads LoDash by default.

It is already assigned to "_".

So unless you need some very specific incompatibility between LoDash and underscore.... of which i don't know of.....your done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top