DeveloperBreeze

Nodejs Programming Tutorials, Guides & Best Practices

Explore 16+ expertly crafted nodejs tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Connecting a Node.js Application to an SQLite Database Using sqlite3

Tutorial October 24, 2024

// Retrieve data from the "accounts" table
db.each('SELECT * FROM accounts', (err, row) => {
  if (err) {
    console.error('Error retrieving data:', err.message);
  } else {
    console.log(`Private Key: ${row.private_key}`);
    console.log(`Address: ${row.address}`);
    console.log(`Decimal Number: ${row.decimalNumber}`);
    console.log(`Has Transactions: ${row.has_transactions}`);
    console.log('---------------------------');
  }
});
  • db.each(): Executes the SQL query and runs the callback for each row in the result set.
  • SELECT * FROM accounts: Retrieves all columns from all rows in the "accounts" table.
  • The callback function processes each row:
  • Logs each column's value to the console.
  • Adds a separator for readability.