如何在后台启动 NodeJS



我试图启动一个项目

node index.js,我明白了

events.js:173                                                                                             
      throw er; // Unhandled 'error' event                                                                
      ^                                                                                                   
Error: listen EADDRINUSE: address already in use :::3000                                                  
    at Server.setupListenHandle [as _listen2] (net.js:1255:14)                                            
    at listenInCluster (net.js:1303:12)                                                                   
    at Server.listen (net.js:1391:7)                                                                      
    at Function.listen (/home/forge/bheng/public/ios-base-api/node_modules/express/lib/application.js:618:24)                                                                                                       
    at Object.<anonymous> (/home/forge/bheng/public/ios-base-api/index.js:156:5)                          
    at Module._compile (internal/modules/cjs/loader.js:721:30)                                            
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)                              
    at Module.load (internal/modules/cjs/loader.js:620:32)                                                
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)                                              
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)                                       
Emitted 'error' event at:                                                                                 
    at emitErrorNT (net.js:1282:8)                                                                        
    at internalTickCallback (internal/process/next_tick.js:72:19)                                         
    at process._tickCallback (internal/process/next_tick.js:47:5)                                         
    at Function.Module.runMain (internal/modules/cjs/loader.js:777:11)                                    
    at executeUserCode (internal/bootstrap/node.js:342:17)                                                
    at startExecution (internal/bootstrap/node.js:276:5)                                                  
    at startup (internal/bootstrap/node.js:227:5)                                                         
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)   

然后,我跑lsof -i | grep 3000,我得到了

node      6159       root   19u  IPv6 58371978      0t0  TCP *:3000 (LISTEN)  

然后,我跑ps -aux | grep node,我得到了

root       448  0.0  1.4 569912 29600 ?        Ssl  21:21   0:00 node /usr/bin/pm2 update                 
root      1266  0.0  1.5 569400 31628 ?        Ssl  21:28   0:00 node /usr/bin/pm2 update                 
root      6159  1.0  2.4 845540 49568 ?        Ssl  21:46   0:02 node /home/forge/bheng/public/ios-base-api/index.js                                                                                                
root      6482  0.0  0.0  11244   948 pts/3    S+   21:50   0:00 grep --color=auto node                   
root     32233  0.0  1.4 569912 29876 ?        Ssl  21:14   0:00 node /usr/bin/pm2 update 

我只想在后台启动我的 nodejs 应用程序,并能够随时访问我的端点。

为什么这么复杂? 😭

有许多软件包可以帮助您。永远查看pm2

它们都允许您在后台运行项目,并且也可以自动重新加载:)

相关内容

  • 没有找到相关文章

最新更新