1.0.2 • Published 3 years ago

if-main v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

if-main CI

yarn add if-main
// my-file.mjs
import ifMain from 'if-main';

ifMain(import.meta.url, async ([name]) => {
  console.log(`Hello, ${name}!`);
  // do stuff if the current file, is also the main file for the program
  // node <current-file>
  // if you want to exit with a non zero status code, throw an exception
  //   throw new Error('something went wrong');
  // if you want to exit with a specific status code
  //   process.exitCode = 99;
});
node ./my-file.mjs world
> Hello, world!

why ?

because