跳转到内容
项目模板·Pro

无依赖的 Node.js JSON API

基于 node:http 的笔记 API:创建、列出、修改、删除,带输入校验和 JSON 错误信息,数据保存到文件。无需安装任何东西:在 server.js 上点 Run,应用自带的 Node.js 会在 localhost:3000 启动它。附带测试。

安装它需要 PocketCode Pro。

如果你的 Android 设备上装了 PocketCode,这会在应用里打开此页面。

预览

文件

README.md
package.json
server.js
src/app.js
src/store.js
test/api.test.js

README.md

# Notes API on Node.js, no dependencies A JSON API for notes built on `node:http`: create, list, read, update and delete, with input checks, clear error messages and a request log. Notes are saved to `data/notes.json` after every change. There is nothing to install: no npm packages, no framework. ## Run it in PocketCode 1. Open `server.js` and tap Run. The app's own Node.js starts it; the Run panel shows `Notes API on http://localhost:3000`. 2. Open `http://localhost:3000` in the DevBrowser (or in the phone's browser) to see the list of endpoints. 3. Try the API from the terminal, or from any HTTP client: ```sh curl -X POST localhost:3000/api/notes -H 'content-type: application/json' -d '{"text":"Buy milk"}' curl localhost:3000/api/notes ``` 4. Tap Stop in the Run panel to end it. You don't need the Linux environment to run the server. `curl` and `npm` are in the terminal's Linux environment with Node.js. ## Run the tests - Open `test/api.test.js` and tap Run. - Or, in the terminal: `npm test`. The tests start the server on a free port with the notes in memory, so they never touch `data/notes.json`. ## Endpoints | Method and path | Body | Answer | |---|---|---| | `GET /health` | | `{"ok": true}` | | `GET /api/notes` | | All notes, oldest first | | `POST /api/notes` | `{"text": "..."}` | 201 and the new note | | `GET /api/notes/:id` | | The note, or 404 | | `PATCH /api/notes/:id` | `{"text"?: "...", "done"?: true}` | The updated note |

此预览已截短。安装后可获得完整内容。

1.0.0 的变更

首个版本。

相关

Express + SQLite 任务 APIPro项目模板基于 Express 5 的任务 API,支持筛选、分页并附带测试。数据存入 node:sqlite,无需编译原生模块。需要带 Node.js 22.13 或更新版本的 Linux 环境;npm install 约下载 3.5 MB。纯 JavaScript 待办清单Pro项目模板用纯 JavaScript 模块写的待办清单:添加、原地编辑、勾选、筛选、清除已完成,数据保存在 localStorage。逻辑部分带有 Node 内置测试运行器的测试。在 DevBrowser 和应用自带的 Node.js 中运行,不需要 Linux。Markdown 静态网站Pro项目模板用 Markdown 写页面,再构建成带统一布局和菜单的静态 HTML 网站。构建脚本约 110 行 Node.js,可以随意修改,唯一的依赖是 marked。在 DevBrowser 中打开结果。首次 npm install 需要 Linux 环境。Rust 命令行:行数统计Pro项目模板用 Rust 写的命令行工具,按语言统计文件夹里的代码行、注释行和空行。这是一个没有依赖的 Cargo 项目,带单元测试。需要 Linux 环境中的 Rust 和 Cargo(约 370 MB)。FastAPI 短链接服务Pro项目模板用 Python、FastAPI 和 SQLite 写的短链接服务。生成短代码、跳转并统计点击,附带单页表单和 pytest 测试。需要 Linux 环境中的 Python 3.10 或更新版本及 pip;会安装 14 个固定版本的包。Next.js + Tailwind + i18nPro项目模板Next.js 15 项目,带 next-intl 和 Tailwind CSS,在 /en 和 /es 提供一个英语和西班牙语页面。深色模式跟随系统。需要带 Node.js 的 Linux 环境;首次 npm install 约下载 400 MB。