Muvi Blogs

Beyond The Buzz- Latest Insights From Muvi

Please wait while we enable your Account

0%

Contacting Amazon Web Services
Deploying Cloud Servers, Storage, Transcoding & Database Servers
Deploying Global CDN
Deploying Firewall & Enabling Security Measures
Deploying the CMS & Admin Module
Deploying Website, Mobile & TV Apps framework
Creating your FTP account
Finishing up all the modules
Preparing for launch

Node forever js on any Virtual Machine 15 March 2021

Hey everyone we are aware of one thing Node js apps runs only after we start the node services but still it will stop once we close the terminal. Moreover this happens even in the local system itself and what will happen if this happens when ur using the Virtual Machines. 

Have you ever faced the issues like the Virtual Machine throws up error like 

client_loop: send disconnect: Broken pipe

Yes, this happens always while working with cloud and this is where the package Forever Js comes in handy. 

This is going to be where I will uncover all the useful commands which are required for Forever Js. Now let’s get started, but before getting started let install forever js.

Code is as follows,

sudo apt-get update

sudo su

npm i forever -g

The next step is to create a test node js application which we will use for this forever application. 

Note: 

Guys here I am using an EC2 Server instance and as usual I just grabbed whatever is under the free tier limit i.e. ubuntu or any linux based OS.

Here is the code, first create a server.js file

Once you do this just verify whether it is working fine or not

 

Now visit the browser with the IP which is assigned to your EC2 instance so that you can verify that as shown below

Alright, I guess we now have our beloved server running successfully. 

Now all that is left is just to make use of the forever js codes.

Forever Commands

Forever Start 

Usually, we start our server by running the code as node server.js but here there will be a small change using the code while running and the code is as follows,

forever start server.js

Forever list

Alright now we can verify using the forever list command

This command is actually used for listing all the scripts which are running forever and it doesn’t stop here. It also shows us the location, process id, up-time and also the details of the log file name of each script that’s running.

Forever Stop

The next command is the stop, yes if there is a start then there will be a stop defenitely. 

We can stop using the file name of the script you want to stop. 

Code is as follows,

forever stop server.js

With this command you have to reach the specific location of the file where the node application is running and only then stop or else it will not work properly.

Alright, what if you want to stop a file based on uid.

Forever stop 0

Well, whenever you start or else list using the forever command you will be displayed with an output of whichever script is running with a uid. So we can also stop using those commands rather than typing out the name of the script file. You can verify by using the start or list command. Now type the following commands,

forever stop o

Even here you can see the uid which I spoke about.

Forever Stopall

Alright if you wish to stop everything that’s running simple stopall, but there are two commands one is forever command and the other one is usual node command.

Forever Logs

If you wish to find the logs then you can just use the following code 

forever logs

It will list the path of each and every script which is running along with the uid.

Now that we stop the forever script and verify our browser and it should throw up the following screen, 

For this, you can use any commands i.e. the normal node command or forever command,

killall node

forever stopall

Now you can use the forever start command and close the EC2 instance terminal and then verify for yourself.

I guess I have given details of most of the Forever js Commands and the rest of the few other commands I will give you guys and do try it out.

Commands:

forever restart server.js

forever restart 0 –> restarts uid o script alone

forever restartall –> restarts all running forever scripts

forever -h –> -h, –help: Command line help information

forever config –> lists all forever user configurations

forever clear –> clears the specified forever config by its key

forever cleanlogs –> deletes all historical forever log files

forever set –> defines a forever config value for a unique key

You can find the server.js file in my GitHub.

 

Don't forget to share this post!


Narendiran Krishnan
AI blogger. Inspiring & working towards a better future through technology & Artificial Intelligence with Hands-on experience in Cloud stacks like --> Azure, AWS, IBM, Open Stack and worked with Terraform for automation of Cloud Infrastructure as a service. Deep Reinforcement Learning (Unity, did TensorFlow code migration), Synthetic Data (Unity), and RASA Chatbot... Join me in the quest.

Latest Posts

Start Muvi One 14-days Free Trial

No Credit Card Required

Your website will be at https://www.yourname.muvi.com, you can change this later.

Related Blogs
Enhance Your Sports Live Streaming With Polling and Live Chat

Enhance Your Sports Live Streaming With Polling and Live Chat

  The season of sports live streaming is here. As we stand in the mid-way of the largest Football tournament,...

04 December 2022
The Rise of Live Streaming & Merchandising in the Sports Sector

The Rise of Live Streaming & Merchandising in the Sports Sector

  The sports streaming industry has grown significantly over the past decade resulting in a significant shift in the live...

02 December 2022
Enhance Customer Experience and build new relation with Video Hosting Solution for Financial Institutions

Enhance Customer Experience and build new relation with Video Hosting Solution for Financial Institutions

  Video banking solutions are on rise these days. Financial institutions have leveraged the way of serving their customers digitally....

01 December 2022
How MUVI Uses S3+CloudFront to Deliver Global OTT Platforms with Zero Downtime

How MUVI Uses S3+CloudFront to Deliver Global OTT Platforms with Zero Downtime

  OTT is now everywhere. Be it your mobile or smart TV, OTT has become the first line of entertainment...

01 December 2022
EST (Electronic Sell Through) - The What, Why and How

EST (Electronic Sell Through) - The What, Why and How

  Electronic Sell Through (EST) has been a game changer since last year because the acquisition of digital movies and...

30 November 2022

Try Muvi One
Free for 14 days

Launch your Multi-Screen Streaming Service
Instantly
START FREE
close-link