メインのindex.jsファイルからモジュールを呼び出す必要があります
これが私のモジュールです
const request = require('./rq.js');
const callback = require('./callback.js')
const url = `https://localhost.3000/${id}`;
request(url, callback)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
})
module.exports = page; //Tell me how to export all code from module
これが私のindex.jsファイルです
const Methods = {
page: require('./page.js'),
}
module.exports = //What i need to code here?
私が呼び出しにモジュールを与えるものからのファイル:
const main = require('./index.js');
main.page({id: 'id'})
.then(console.log);
では、そのようなpage.jsファイルを呼び出すために何を変更する必要がありますか?
メインファイルでpromiseが返されることを期待しているため、page.jsに次の変更を加えます。
const request = require('./rq.js');
const callback = require('./callback.js')
function page({id}) {
const url = `https://localhost.3000/${id}`;
return request(url, callback)
}
module.exports = {page: page} //Tell me how to export all code from module
Mehods.jsに次の変更を加えます
const Methods = {
page: require('./page.js').page,
}
module.exports = Methods;
これが機能するかどうかを確認します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加