photo credit: Dvouramenná váha; Two-pan balance weight via photopin (license)

How to connect to a SQLite database in NodeJS

In my series of posts about my first real steps in NodeJS I share with you tiny bits of code that I took the time for to figure out, so you don’t have to. In this article I’ll show you how easy it is to connect to a SQLite database in NodeJS:

The first thing you have to do, is install the sqlite3 npm package for your NodeJS Project:

Or if you want to also save it as a dependency to your NodeJS project:

And now for the example script:

This script creates an empty database if it doesn’t exist (with a table) and then inserts some data in it.
It’s a short, minimal example, but it shows the basic steps to take when you want to work with a SQLite database in NodeJS.

Visitors give this article an average rating of 3.4 out of 5.

How would you rate this article?

Leave a Reply