项目模板·Pro
Express + SQLite 任务 API
基于 Express 5 的任务 API,支持筛选、分页并附带测试。数据存入 node:sqlite,无需编译原生模块。需要带 Node.js 22.13 或更新版本的 Linux 环境;npm install 约下载 3.5 MB。
安装它需要 PocketCode Pro。
如果你的 Android 设备上装了 PocketCode,这会在应用里打开此页面。
预览
文件
README.md
package-lock.json
package.json
server.js
src/app.js
src/db.js
src/errors.js
src/routes/tasks.js
src/validate.js
test/tasks.test.jsREADME.md
# Tasks API: Express + SQLite A REST API for tasks with Express 5 and SQLite: create, list, read, update and delete tasks, filter the list by state, tag or text, and page through it. Input is checked and errors come back as JSON. The database is `node:sqlite`, which is built into Node.js 22.13 and newer, so the only package is Express (about 65 small packages, 3.5 MB, all JavaScript). Comes with tests. ## Run it in PocketCode You need the app's Linux environment with Node.js 22.13 or newer and npm (the Developer pack in Terminal › Linux includes both). Check with `node --version`. 1. Open the terminal in this project's folder (Open Terminal Here, in the editor menu). 2. Install Express (needs internet the first time): ```sh npm install ``` 3. Start the server: ```sh npm start ``` The terminal shows `Tasks API on http://localhost:3000`. `npm run dev` does the same and restarts it when you save a file. Some Node.js versions also print `ExperimentalWarning: SQLite is an experimental feature`; the API works the same. 4. Open http://localhost:3000 in the DevBrowser (or in the phone's browser) to see the list of endpoints. To try the API, open a second terminal tab: ```sh curl -X POST localhost:3000/api/tasks -H 'content-type: application/json' -d '{"title":"Buy milk","tag":"home"}' curl 'localhost:3000/api/tasks?done=false' curl -X PATCH localhost:3000/api/tasks/1 -H 'content-type: application/json' -d '{"done":true}' ```此预览已截短。安装后可获得完整内容。
1.0.0 的变更
首个版本。