V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
mercurylanded
V2EX  ›  Node.js

nodejs中能够判断这个模块是程序入口么。就像python里面 if __name__ == 'main' : 这样的。

  •  
  •   mercurylanded · 2012-12-19 15:14:41 +08:00 · 3497 次点击
    这是一个创建于 4145 天前的主题,其中的信息可能已经有所发展或是发生改变。
    2 条回复    1970-01-01 08:00:00 +08:00
    jackyz
        2
    jackyz  
       2012-12-19 18:31:22 +08:00
    if(!module.parent){
    console.log('我是程序入口');
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5709 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 02:23 · PVG 10:23 · LAX 19:23 · JFK 22:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.