Project template·Pro
Node.js JSON API without dependencies
A notes API on node:http: create, list, update and delete notes, with input checks and JSON errors, saved to a file. You don't install anything. Tap Run on server.js and the app's own Node.js starts it on localhost:3000. The project includes tests.
You need PocketCode Pro to install it.
If PocketCode is installed on your Android device, this opens the page in the app.
Preview
Files
README.md
package.json
server.js
src/app.js
src/store.js
test/api.test.jsREADME.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 |This preview is shortened. You get the full content when you install it.
Changes in 1.0.0
First version.