jdscardoso
jdscardoso

Reputation: 291

NodeJS - Restart aplication at given time

I have made my speech recognizer server with nodejs, but it happens that I have a tiny memory leak in each recognition that is driving me crazy. While I am fixing this problem I want to use the actual version. To do that I am thinking in a routine, that restarts the nodejs at given time.

How can I do that?

Upvotes: 0

Views: 62

Answers (3)

jdscardoso
jdscardoso

Reputation: 291

This can accomplish part of almost of I want. Using .bat file, the one possible solution could be:

@echo off
REM nodevars.bat directory
:loop
cd C:\Program Files (x86)\nodejs 
call nodevars.bat 
::PAUSE
cd C:\app_directory
::PAUSE 
REM Initialize nodejs server
start node app.js
::node app.js ::equivalent
REM do the timeout
timeout /t 5 > null REM 5 seconds
taskkill /f /im node.exe >null
REM safety close
timeout /t 2 >null REM 2 Seconds
goto loop

Upvotes: 0

Aishwat Singh
Aishwat Singh

Reputation: 4469

try nodemon

npm install -g nodemon --save

then start ur app as nodemon app.js

Upvotes: 1

Sven
Sven

Reputation: 5265

I recommend fixing the memory leak so it doesn't slide - but in the meantime you can use forever in your code to reload itself. You would basically have to wrap forever around your entire application.

Upvotes: 1

Related Questions