本文介紹了打印所有已安裝的 node.js 模塊的列表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在我正在處理的 node.js 腳本中,我想將所有 node.js 模塊(使用 npm 安裝)打印到命令行.我該怎么做?
In a node.js script that I'm working on, I want to print all node.js modules (installed using npm) to the command line. How can I do this?
console.log(__filename);
//now I want to print all installed modules to the command line. How can I do this?
推薦答案
使用 npm ls (甚至還有json輸出)
Use npm ls (there is even json output)
來自腳本:
test.js:
function npmls(cb) {
require('child_process').exec('npm ls --json', function(err, stdout, stderr) {
if (err) return cb(err)
cb(null, JSON.parse(stdout));
});
}
npmls(console.log);
運行:
> node test.js
null { name: 'x11', version: '0.0.11' }
這篇關于打印所有已安裝的 node.js 模塊的列表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!