简体   繁体   English

如何在生产服务器上测试,调试和查看Node js应用程序的控制台日志消息

[英]How to test, debug and view console log message of Node js app on production server

I have a ubuntu server, on which node js app is running. 我有一个ubuntu服务器,在该服务器上运行node js应用程序。 That app is developed from Sails mvc framework. 该应用程序是从Sails mvc框架开发的。 I am asked to fix some server side js code. 我被要求修复一些服务器端js代码。 But the problem is I don't how to test, and debug those code. 但是问题是我不怎么测试和调试那些代码。

First of all, it's linux server without UI, I can't test from browser by localhost, since the program is triggered from HTTP request. 首先,它是没有UI的linux服务器,由于程序是从HTTP请求触发的,因此我无法通过本地主机从浏览器进行测试。

Secondly, it is also unlikely to debug from build-in debugger command line client, for the same reason as the first one. 其次,出于与第一个相同的原因,也不太可能从内置调试器命令行客户端进行调试。 Maybe I just don't know how... 也许我只是不知道如何...

Third, I saw there is some console.log('...') codes, but I don't know where to find the log file. 第三,我看到有一些console.log('...')代码,但是我不知道在哪里可以找到日志文件。

Hopefully someone could provide some opinions. 希望有人可以提供一些意见。 Thanks very much. 非常感谢。

You don't need the browser - you can do fake requests with curl : 您不需要浏览器-您可以使用curl进行虚假请求:

curl -v -XPOST localhost/path -d 'variable=test'

Probbably your app has some logging (logs are saved to a file), so search for it: 您的应用可能有一些日志记录(日志已保存到文件中),因此请搜索它:

  • search for the node process PID: 搜索节点进程的PID:

     ps aux | grep node 

    or 要么

     ps aux | grep <your application name> 
  • view open files of the node process and find your logs 查看节点进程的打开文件并找到您的日志

     ls -l /proc/<node_app_pid>/fd 

Resources: 资源:

Sails has it's own built in test suite, using mocha . Sails使用mocha拥有自己的内置测试套件。

See the Sails documentation on how to test and debug your application. 请参阅Sails 文档,以了解如何测试和调试应用程序。

NodeJS exists outside your browser, as a standalone runtime, so it does not log to your chrome dev console. NodeJS作为独立的运行时存在于浏览器外部,因此它不会登录到chrome开发者控制台。 A node app is started from the terminal using the command node <filename.js> or nodejs <filename.js> . 使用命令node <filename.js>nodejs <filename.js>从终端启动节点应用程序。 Since you mentioned sails, maybe you are running it as a forever process 既然您提到风帆,也许您将其作为一个forever过程

To check if you are running it as forever process: 要检查您是否将其作为永久进程运行:

  1. Open linux terminal on the server that the app is running on. 在运行应用程序的服务器上打开linux终端。
  2. type forever list forever list
  3. Find the entry containing the name of your main file 查找包含主文件名的条目
  4. Then get the name of the .log file associated with it 然后获取与其关联的.log文件的名称
  5. To see the logs do tail -f <log file path> 要查看日志,请执行tail -f <log file path>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM