'running node.js using systemd but systemd couldn't find html

Using raspberry pi4, express for server, get data through socket.io, and send the data to client side(html) and log on rest API.

The problem is that systemd couldn't find html file. When I run $ sudo systemctl start FileToServer.service HTML shows me this error message.

Error: ENOENT: no such file or directory, stat '/index.html' 
  1. $ node server.js is working. and i can see what i want and there isn't any error messages.
  2. sudo systemctl start FileToServer.service can also run the server.js
  3. I checked sudo systemctl status FileToServer.service, and confirmed active is active(running).
  4. I also run using $ sudo su and it didn't work

What can i do ?

[Unit]
Description=usb lte

[Service]
Type=simple
ExecStart=/usr/bin/node /home/pi/Desktop/rpi4_clientside/server.js
Restart=on-failure
#User=pi
#User=root
#Group=root

[Install]
WantedBy=multi-user.target

This is the code snippet i'm struggling. server.js

    import express from "express";
    const app = express();
    import { SerialPort } from "serialport";
    import { ReadlineParser } from "@serialport/parser-readline";

    import { createServer } from "http"; 
    import { Server } from "socket.io";
    const httpServer = createServer(app);
    const io = new Server(httpServer, {});

    import axios from "axios";
    import path from 'path';
    const __dirname = path.resolve();
    const PORTnum = 3000;
    const publicIp = "222.33.222.33"
    const localIp = "172.3.1.2"
    const serverSidePort = "5500"
    let api_url = `http://${publicIp}:${serverSidePort}/gps`;

    httpServer.listen(PORTnum, () => {
      console.log(`it's alive on http://localhost:${PORTnum}`);
    })

    app.use(express.json())

    app.get("/", (req, res) => {
      // console.log(res);
      res.sendFile(__dirname + "/index.html");
    });



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source