Ask coding questions

← Back to all posts
How do I connect Javascript to sqlite?
ia13ru (43)

How would I connect javascript to sqlite when Javascript is being used with HTML?

Answered by xfinnbar (21) [earned 5 cycles]
View Answer
Comments
hotnewtop
xfinnbar (21)

The short answer is, you can't. However there is a way around it using a server.
HTML/CSS/JS is a client. You need to connect to a server to get the page, database or any other type of dynamic content. Repl.it handles the server for you when you choose HTML in the languages menu. You'll need to write your own server.
From my experience, NodeJS and Python are the two best languages to write a server in, go for NodeJS if you care about a lot of performance, but for most tasks, Python will suffice. If you've only got experience in JavaScript, use NodeJS.
Once you've set up your server, add the sqlite3 (built-in) module if you use Python, and the NPM package sqlite3 (https://www.npmjs.com/package/sqlite3).

I have posted a Quart Python server template on my profile if you need somewhere to get started and you choose Python.