javascript - How to test, debug and view console log message of Node js app on production server - Stack Overflow

I have a ubuntu server, on which node js app is running. That app is developed from Sails mvc framework

I have a ubuntu server, on which node js app is running. That app is developed from Sails mvc framework. I am asked to fix some server side js code. 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.

Secondly, it is also unlikely to debug from build-in debugger mand 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.

Hopefully someone could provide some opinions. Thanks very much.

I have a ubuntu server, on which node js app is running. That app is developed from Sails mvc framework. I am asked to fix some server side js code. 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.

Secondly, it is also unlikely to debug from build-in debugger mand 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.

Hopefully someone could provide some opinions. Thanks very much.

Share Improve this question edited Apr 3, 2015 at 23:04 Travis Webb 15k9 gold badges59 silver badges111 bronze badges asked Jan 7, 2015 at 9:09 user2321728user2321728 1,3732 gold badges12 silver badges17 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

You don't need the browser - you can do fake requests with 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:

    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:

  • List Open Files for Process

Sails has it's own built in test suite, using mocha.

See the Sails documentation on how to test and debug your application.

NodeJS exists outside your browser, as a standalone runtime, so it does not log to your chrome dev console. A node app is started from the terminal using the mand node <filename.js> or nodejs <filename.js>. Since you mentioned sails, maybe you are running it as a forever process

To check if you are running it as forever process:

  1. Open linux terminal on the server that the app is running on.
  2. type 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
  5. To see the logs do tail -f <log file path>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745375421a4624975.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信