This is an example of a simple TODO application that uses Vite Server Actions and Svelte to demonstrate a real-world use case, where server actions are used to save, list, and delete TODOs, with data stored in a JSON file.
git clone
cd examples/todo-app
npm install
npm install
npm run dev
Open http://localhost:5173 to view it in your browser. (Note: The port may vary, check the console output for the correct port)
Server Actions works in production mode by bundling the server into a single file that can be run with Node.js.
Here's how you can build and run the example in production mode:
# Install dependencies and build the project
npm install
npm run build
# Run the generated express.js server
node dist/server.js
Open http://localhost:3000 to view it in your browser.
The important files and directories in this example are:
src/
- Contains the client-side Svelte applicationsrc/actions/
- Contains the server action files (functions that are run on the server, note the.server.js
suffix)src/actions/todo.server.js
- Contains server actions for managing TODOssrc/actions/auth.server.js
- Contains a dummy server action for demonstration purposes
src/App.svelte
- The main Svelte component that imports and calls the server actions to manage TODOs.vite.config.js
- Vite configuration file that includes the Server Actions pluginserverActions()
dist/
- The output directory for the production build.dist/server.js
- The express server that serves the client-side application and the server actions (automatically created by the plugin)todos.json
- The JSON file where the TODOs are stored (serves the purpose of a simple database for this example)