LoginSignup
1
1

More than 5 years have passed since last update.

node.jsスクリプトの書き始めスニペット

Last updated at Posted at 2018-07-21

node.jsで簡単なスクリプトを書く際にasync対応と終了コードを指定したかったので
スニペットにしました。

'use strict';

async function main() {
    let ret = "hello";
    // throw new Error('reject!!');
    return ret;
}

if (require.main === module) {
    main()
        .then(resolve => {
            console.log(resolve);
            process.exit(0);
        })
        .catch(reject => {
            console.log(reject);
            process.exit(1);
        });
}
1
1
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
1
1