Friday, May 18, 2018

loop in things from the node_modules folder into your Express application

var _ = require('lodash');

 
 

...at the top of app.js (or another file looped in) is going to loop in lodash assuming there is a folder in the node_modules folder titled "lodash" to be found. You may then do all of the lodashy things with a dot off of the underscore downstream in code like this:

_.groupBy(['one', 'two', 'three'], 'length');

 
 

Per the documentation the line of code above gives us:

{ '3': ['one', 'two'], '5': ['three'] }

 
 

It looks like you can do some fat arrow stuff like x => x.length for the second argument too but I digress.

No comments:

Post a Comment