'ReferenceError: _ 未定义':在 node.js 中使用 LODASH 模块时显示错误,_.isString()

Sau*_*abh 0 node.js referenceerror lodash

我已经开始通过各种视频教程学习 node.js。

下面的代码不起作用,输出应该是'false'firstconsole.log()和'true'second console.log()。

这是我在 app.js 中的代码:

console.log('Starting app');     
console.log(_.isString(true));    
console.log(_.isString('Saurabh'));
Run Code Online (Sandbox Code Playgroud)

输出

在 CMD 中:

saurabh@kumar:/var/www/html/notes-node$ nodejs app.js        
    Starting app        
    /var/www/html/notes-node/app.js:25        
    **console.log(_.isString(true));**        
                ^
    **ReferenceError: _ is not defined**        
        at Object.<anonymous> (/var/www/html/notes-node/app.js:25:13)
        at Module._compile (module.js:410:26)
        at Object.Module._extensions..js (module.js:417:10)
        at Module.load (module.js:344:32)
        at Function.Module._load (module.js:301:12)
        at Function.Module.runMain (module.js:442:10)
        at startup (node.js:136:18)
        at node.js:966:3
    saurabh@kumar:/var/www/html/notes-node$ npm -v
    3.5.2
Run Code Online (Sandbox Code Playgroud)

Ali*_*zmi 7

您必须使用 npm 安装 lodash,例如

npm install --save lodash
Run Code Online (Sandbox Code Playgroud)

然后,你必须要求它在文件中说app.js像

const _ = require('lodash');
Run Code Online (Sandbox Code Playgroud)

你必须按照这些步骤在你的项目中使用 lodash