Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungI audited my own ML linter and had to withdraw its best evidence(21.09.2026 um 22:54 Uhr)
Sichere ProgrammierungQuantum Result Validation for Distributed Computing Systems(21.09.2026 um 22:54 Uhr)
Sichere ProgrammierungJWT Authentication and Role-Based Access Control in LocalHands(21.09.2026 um 22:56 Uhr)
Sichere ProgrammierungStochastic Parrot or Alien Mind?(21.09.2026 um 22:56 Uhr)
Sichere ProgrammierungBuilding AI for the Physical World Is a Different Engineering Problem(21.09.2026 um 22:58 Uhr)
Sichere ProgrammierungI audited my own ML linter and had to withdraw its best evidence(21.09.2026 um 22:54 Uhr)
Sichere ProgrammierungQuantum Result Validation for Distributed Computing Systems(21.09.2026 um 22:54 Uhr)
Sichere ProgrammierungJWT Authentication and Role-Based Access Control in LocalHands(21.09.2026 um 22:56 Uhr)
Sichere ProgrammierungStochastic Parrot or Alien Mind?(21.09.2026 um 22:56 Uhr)
Sichere ProgrammierungBuilding AI for the Physical World Is a Different Engineering Problem(21.09.2026 um 22:58 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

How to use SQLite3 in Node.js (full clear documentation for beginners)

SQLite3 is the file based database No server needed. Just one file → .db You can embed this DB inside your desktop app, CLI tool or small web backend. For using SQLite3 we need a SQLite3 package and web admin panel. You can install i…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

SQLite3 is the file based database




  • No server needed.

  • Just one file → .db



You can embed this DB inside your desktop app, CLI tool or small web backend.



For using SQLite3 we need a SQLite3 package and web admin panel. You can install it from NPM




npm install sqlite3 sqlite3-admin









Making a database connection



First of all for using SQLite3 database you need a making connection (for instance create a file db.js):




const sqlite3 = require('sqlite3').verbose();

// Opens database file
// if file not exists → it will create automatically
const db = new sqlite3.Database('./app.db');






Run your db.js:




node db.js






And then we’ll connect it to sqlite3 admin panel for viewing it visually (for checking that our codes runs correctly or not). For connecting your db you need to prompt your CLI like this command:




npx sqlite3-admin app.db






If your database’s name isn’t app.db you can change it.



Let’s check:





So we made our SQLite3 database and connected it to web admin panel.






Creating a table



const sqlite3 = require('sqlite3').verbose();

const db = new sqlite3.Database('./app.db');



db.run(

CREATE TABLE IF NOT EXISTS users(

id INTEGER PRIMARY KEY AUTOINCREMENT,

name TEXT,

email TEXT

)

, (err)=>{

if(err) console.log("Error: ", err);

else console.log("Table created ✅")

});

Run:




node db.js






Let’s check:





So we created our first table successfully!






Insert data



Now we’ll try to insert data to our users table:




const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./app.db');

const name = "John";
const email = "[email protected]";

db.run(`INSERT INTO users(name, email) VALUES(?, ?)`, [name, email], function(err){
if(err) console.log("Error: ", err);
console.log("Inserted row ID:", this.lastID);
});






Important:





  • ? placeholders avoid SQL injection


  • this.lastID gives auto incremented ID








Read (SELECT) data






const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./app.db');

db.all("SELECT * FROM users", [], (err, rows) => {
if (err) throw err;

rows.forEach(row => {
console.log(row.id, row.name, row.email);
});
});
db.all() returns array of rows








But if you want get only one row like using this query SELECT * FROM users WHERE id = 1 you should use db.get().






Update row






const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./app.db');

db.run(
`UPDATE users SET name=? WHERE id=?`,
["Mike Tyson", 1],
function(err) {
if (err) throw err;
console.log("Rows changed:", this.changes);
}
);






this.changes shows how much rows changed








Delete row






const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./app.db');

db.run(
`DELETE FROM users WHERE id=?`,
[1],
function(err) {
if (err) throw err;
console.log("Rows deleted:", this.changes);
}
);











Close the database






db.close();






Best practice → close DB only when app exit.




const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./app.db');

db.serialize(() => {
db.run("CREATE TABLE IF NOT EXISTS posts(id INTEGER PRIMARY KEY, title TEXT)");

db.run("INSERT INTO posts(title) VALUES(?)", ["Hello world"]);

db.all("SELECT * FROM posts", [], (err, rows)=>{
console.log(rows);
});
});

// db.close()






db.serialize() run all queries inside it one-by-one in order (synchronously guaranteed order).



Without serialize() → sqlite3 runs queries in parallel (async) and order isn’t guaranteed.



Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to use SQLite3 in Node.js (full clear documentation for beginners)

Thematisch verwandte Begriffe: SQLite3, Nodejs, full, clear · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-79918 | MaxKB is an open-source AI assistant for enterprise. Prior to version 2.…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick