Host website with Node Express not work with Windows Task Scheduler

24 Views Asked by At

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?

1

There are 1 best solutions below

0
ewokx On BEST ANSWER

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