Search code examples
node.jsexpresswindows-task-scheduler

Host website with Node Express not work with Windows Task Scheduler


I write a simple website, and host it with Node Express.

const express = require('express')
const app = express()
app.use(express.static('./'))
app.listen(7100, () => {
    console.log('started')
})

While putting it on server, I want it to be started whenever server restarts. So, I write one bat script and configre a windows task scheduler to run the bat script when server restarts. Here is the bat file conten.

node server.js

But it seems that windows task scheduler never start this node express server. Is there anything wrong with it?


Solution

  • Node needs to actually find the js file and Windows Task Scheduler won't have any information on that.

    So the easiest would be to put the following in your bat file:

    @echo off
    cd <full path which stores the server.js file>
    node server.js