热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

用forever来解决重复重启node服务器的问题

ThisisprobablyonlyapplicabletobeginnersasIcanonlyassumeexperiencedusershavealreadyhadthisi

This is probably only applicable to beginners as I can only assume experienced users have already had this issue and quickly did what I have and found the solution. But for those of you who haven’t then make sure to do this when developing your next Sails application.

Note: I'm assuming you already have Sails installed
Install forever. (Other packages are available for this, but this is what I use)

[sudo] npm install forever -g

Create your new Sails.js application wherever you want

sails new awesomeApplication cd awesomeApplication

Now you want to add a file called .foreverignore

“`nano .foreverignore

Add the following lines to the file

**/.tmp/**
**/views/**
**/assets/**

If you have Sails installed globally then you will have to run the following command, which will add Sails to your application.

npm install sails

Now when you lift your application instead of using

sails lift

you use…

forever -w start app.js # -w to watch for file changes!

Now you can enjoy coding your application and let Forever handle restarting the server when changes are made.

But wait now forever launches it in the background and I can’t see my console.logs…

No problem!, in your terminal find your .forever location generally in your Home folder and run the following

See update for a better way than this…

List running apps to get log file name

forever list

ls #list the files to find the log file 0P9R.log 9UBR.log KqgI.log config.json ehQC.log pids qvyg.log sock
tail -f KqgI.log

To stop your application just run

forever stop app.js

Update

Thanks to zieglar for the tip

Instead of using tail command you can just use forever to stream it out with…

forever logs app.js -f

If you have multiple applications running which are all called app.js you will have to use the index so just grab that from the list (it will be in square brackets) by using

forever list

Start the log using the index

forever logs 2 app.js -f


推荐阅读
author-avatar
手机用户2502908011
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有