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'
sudo systemctl start FileToServer.service can also run the server.jssudo systemctl status FileToServer.service, and confirmed active is active(running).$ sudo su and it didn't workWhat 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");
});