Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (15 sloc) 785 Bytes
tags title
javascript node.js



if (require.main === module) {
  // nodeコマンドから実行された
} else {
  // requireされた

Accessing the main module - Node.js Documentation

When a file is run directly from Node.js, require.main is set to its module. That means that you can determine whether a file has been run directly by testing.

You can’t perform that action at this time.