1
我正在嘗試使用nodejs的WGET方法創建文件下載。我發現這一點:帶有WGET的NodeJS文件下載器?
var exec = require('exec');
// Function to download file using wget
var download_file_wget = function(file_url) {
// extract the file name
var file_name = url.parse(file_url).pathname.split('/').pop();
// compose the wget command
var wget = 'wget -P ' + DOWNLOAD_DIR + ' ' + file_url;
// excute wget using child_process' exec function
var child = exec(wget, function(err, stdout, stderr) {
if (err) throw err;
else console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
});
};
但它說:
Error: Cannot find module 'exec'
是exec
的安裝並導入到另一模塊..或者我怎樣才能使它發揮作用?
哦..'url'沒有解決,但再次'exec',但我不能包括'無功EXEC =需要(「EXEC」 );'是否要安裝? –
你可能想要做'var exec = require('child_process')。exec' - 這個東西在API文檔中很容易找到 - http://nodejs.org/api/ – jimr
oh yaaa!這是它jimr。所以現在我改變了關於'exec'的問題,然後把你的答案作爲新的答案。因爲我想把它作爲一個被接受的答案。謝謝 ;) –