r/node • u/Realto619 • 10d ago
Monaco Editor App Upgrade with node:sqlite
I have a working Monaco Editor app that currently saves records to localStorage that I want to upgrade and save them to sqlite using the newer native node:sqlite functionality. I've tested the database and tables that I created using hard coded data so I know all those Insert statements work.
Now I need to update the code to insert the form data into the database instead of localStorage. I'm thinking of using express to capture the form data but this is the first time using node for this kind of application. There's a lot of information out there on the available options, but not much in the way of a strong recommendation or a consensus method.
So I'm interested in getting recommendations from other devs on how to best go about getting this to work. Is express sufficient or are there other modules/libraries that would make handling the data as seamless as possible?
Since this will probably come up, this is just a personal project and won't be available publicly so I don't have to lock it down with any serious security (other than just a PHP login form to access it).
Thanks in advance!

2
u/GiggleSamurai 10d ago
Express is plenty for this: add `app.use(express.json())`, have the page send the form with `fetch('/records', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) })`, and in that route run your insert as a prepared statement, e.g. `db.prepare('INSERT INTO records (title, body) VALUES (?, ?)').run(req.body.title, req.body.body)` with `db = new DatabaseSync('app.db')` from `node:sqlite`. Using `?` placeholders instead of building the SQL string keeps quotes in the editor content from breaking the query.