重複の可能性:
module.exports 内の別の関数から module.exports 内の「ローカル」関数を呼び出しますか?
アプリケーションの開発に node.js を使用しています。main.js から別のメソッド内で 1 つのメソッドを呼び出す必要があります。どうすればいいですか?
ここで詳細を説明しています。
app.js
app.post('/getNotificationCount', function (req, res) {
res.setHeader('Cache-Control', 'max-age=0, must-revalidate, no-cache, no-store');
res.setHeader('Connection', 'keep-alive');
res.contentType('application/json');
res.setHeader('Expires', new Date().addYears(-10));
try {
//here i have my custom code/logic
//i have to call '/getNotification' method here, i have to pass parameter too..
}
catch (err) {
console.log('\r\n ' + new Date().toString() + ' - Try Catch from /getNotificationCount : ' + err + ' \r\n ');
res.json({ error: 'Forbidden' }, 403);
}
});
app.post('/getNotification', function (req, res) {
res.setHeader('Cache-Control', 'max-age=0, must-revalidate, no-cache, no-store');
res.setHeader('Connection', 'keep-alive');
res.contentType('application/json');
res.setHeader('Expires', new Date().addYears(-10));
try {
//my sql code goes here !!!
//I want retrieve parameter in req.body here...
}
catch (err) {
console.log('\r\n ' + new Date().toString() + ' - Try Catch from /getNotification : ' + err + ' \r\n ');
res.json({ error: 'Forbidden' }, 403);
}
});
これどうやってするの?