szymmis/vite-express

Reload server.ts

Closed this issue · 3 comments

Hi, I can't figure out how to reload my application when editing server.ts, how can I achieve this?

In my case I want to edit the example:

app.get("/message", (_, res) => {
    res.send("Hello from express!")
});

When I edit server.ts nothing happens. F5 key in browser does not help me. For this I have to restart the application manually

Hi @malikiz, every change in server-side code needs an application restart.
If you want to have it automated on file save you can use nodemon. That's a package that create-vite-express templates use. Check out this package.json for an example.

Thanks for the hint, it really works. Just in case, I'll write how to implement this on node 20 and typescript 5 versions:

in package.json:

{
  "type": "module",
  "scripts": {
      "dev": "nodemon --exec \"node --loader ts-node/esm\" ./src/server/server.ts -w ./src/server"
  }
}

in tsconfig.json:

{
  "ts-node": {
    "transpileOnly": true,
  }
}

I'm closing this issue