Search code examples
node.jsgoogle-speech-api

NodeJS Server getting stop on Error


I am very New to NodeJS. I am developing Live Streaming based Speech to text for my web application. It works well but problem is

Sometimes, Nodejs throws an error as 'Request Time-Out' and http server has been stop. then I need to manually re run program again (with command node app.js)

I had used this example here.

Screen shot is bello Please help. And thanks in advance.

enter image description here


Solution

  • You need first to try {} catch(ex){}your exceptions. You may also use pm2 which can handle that autostart if it crashes. When using pm2 please make use of --max-memory-restart option otherwise the app can indefinitly restart and will slow down your server. That option can help you specify the amount of memory the autorestart can consume.

    Install pm2

    npm install -g pm2
    //or
    yarn global add pm2
    

    Run the app

    pm2 start app.js --max-memory-restart 100 --name node-speech 
    

    Using pm2 is even recommanded on the repository readme