Start NPM and Node.js on machine startup using Windows Task Scheduler

ساخت وبلاگ

I want to host my Node.js application in LAN (for testers). What I'm trying to is setting up the Windows task in Task Scheduler.

My task needs to run npm start and node server.js commands to work as two separate processes (1st runs up the microservice that is hosting my static HTML, JS content; and the 2nd is running the Express.js API server.

When I start my task manually it works fine. But the problem is I want it to start automatically after the server was restarted (on startup event).

What happens? - It is actually starting correctly, no errors in history. The processes are working (after I log in), but the page is not reachable (ERR_CONNECTION_TIMED_OUT). I have to stop it and start again manually to make it work.

Here's my task's configuration:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2016-05-19T13:59:25.5552942</Date> <Author>BSGauthor</Author> </RegistrationInfo> <Triggers> <BootTrigger> <Enabled>true</Enabled> <Delay>PT5M</Delay> </BootTrigger> <CalendarTrigger> <Repetition> <Interval>PT30M</Interval> <Duration>P1D</Duration> <StopAtDurationEnd>true</StopAtDurationEnd> </Repetition> <StartBoundary>2016-05-19T13:59:34.7184867</StartBoundary> <ExecutionTimeLimit>PT1H</ExecutionTimeLimit> <Enabled>true</Enabled> <ScheduleByDay> <DaysInterval>1</DaysInterval> </ScheduleByDay> </CalendarTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId>S-1-5-18</UserId> <RunLevel>HighestAvailable</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries> <AllowHardTerminate>false</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <IdleSettings> <StopOnIdleEnd>true</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> <AllowStartOnDemand>true</AllowStartOnDemand> <Enabled>true</Enabled> <Hidden>false</Hidden> <RunOnlyIfIdle>false</RunOnlyIfIdle> <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession> <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine> <WakeToRun>false</WakeToRun> <ExecutionTimeLimit>PT0S</ExecutionTimeLimit> <Priority>7</Priority> <RestartOnFailure> <Interval>PT5M</Interval> <Count>10</Count> </RestartOnFailure> </Settings> <Actions Context="Author"> <Exec> <Command>node</Command> <Arguments>server.js</Arguments> <WorkingDirectory>C:SomeProjectapi</WorkingDirectory> </Exec> <Exec> <Command>npm</Command> <Arguments>start</Arguments> <WorkingDirectory>C:SomeProjectweb</WorkingDirectory> </Exec> </Actions>
</Task>

Recent Questions...
ما را در سایت Recent Questions دنبال می کنید

برچسب : نویسنده : استخدام کار superuser بازدید : 334 تاريخ : جمعه 31 ارديبهشت 1395 ساعت: 20:00