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?

有帮助吗?

解决方案 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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top