search

Home  >  Q&A  >  body text

node.js中创建并启动了一个http server模块后,日后热配置时如何获取它?

直接x=require(http).createServer.listen的话,哪怕是全局变量也只存在于那个进程中。再次打开node.exe是一个新的进程,变量不存在。请教一旦关了命令行界面,如何才能再访问当时启动的上下文去热操作那个x?总不能每次都重启吧

黄舟黄舟2817 days ago713

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 13:20:28

    Global variables only exist in one process and cannot be called across processes. If you want to debug, write it directly in the js file. After modification, you can only restart. js is a 'semi-compiled' language.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:20:28

    Used under linuxnohup node xxxx.js &
    Used under windowsstart node xxx.js

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:20:28

    Configuration like this can be done not in global variables, but in the file system

    reply
    0
  • Cancelreply