LoginSignup
5
4

More than 5 years have passed since last update.

Nodejsでエラーキャッチ

Posted at

すごく軽量で可愛らしいフレームワークなんですが、エラーを吐くと一瞬で死にます。
まるで生まれたての子鹿のような弱さなので、ちゃんとエラーキャッチする癖をつけるべく
備忘録として書いときます。

var path;
try {
path = require.resolve('hoge');
} catch(e) {
    console.log("Error:Cannot hoge,because the file is not exist.");
}
// hogeが存在したときのみ、hogeのフルパスが取得される。
var directedModule = require(path);
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4