NodeJでコードの残りの部分を実行しないようにするにはどうすればいいでしょうか?(process.exit()が実行される最後の行だと言うアプリケーションではありません)。残りのコードがNodeJsを実行するのを止めるには?
通常のjavascriptではexit()がありますが、それはnodejsでは動作しません。以下は
は状況です:
connection.query(sql, [req.session.sessionUserPackagePassword] , function(err, rows, fields) {
if (!err) {
var userFound = false;
for(var i=0; i< rows.length; i++) {
// Make the comparaison case insensitive
if ((rows[i].deliveredToUser).toLowerCase() == `no`) {
userFound = true;
console.log(userFound);
[...]
}
}
if (!userFound) {
res.render('pickup/errorAlreadyDelivered', {});
// exit here
}
console.log(userFound);
// If the query fails to execute
} else {
console.log('Error while performing Query.');
res.render('errorConnection', {});
}
});
connection.end();
// Update the query to say the box has been delivered to user and specify time
// Establish the connection
[...]
res.render('pickup/openPackageClose', {
title: '',
helpButtonURL: '/help/help-dropPackage',
helpButtonTitle: 'Help'
});
});
それがうまくいくかもしれないように、この条件が満たされたとき基本的に、私は
if (!userFound) {
res.render('pickup/errorAlreadyDelivered', {});
// exit here
}
ブロックの実行を停止するには、breakを使用します。 –
実行しないようにするコードをelseブロックの中に置きます。 –
'connection.end()'を呼び出さずに終了してもよろしいですか? –