Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Unable to connect to disk database using SQLite with Express

So I am writing an API for my front-end app to save login authentication. For some reason, I am unable to connect to the SQLite database I have made using DB Browser. Every time I try to connect it seems to connect to an in memory database. I have tried doing this mutiple times but have no luck, please help.

Here is the file structure: File structure

Note: the main file is admin-route.js and admin.db

I am currently trying to get it to work using the /admin/register route.

Here is the code:

const router = require('express').Router()
const sqlite = require('sqlite3').verbose()

const admin = require('../admin')

let db = new sqlite.Database('../admin.db', (err) => {
    if(err) {
      console.error(err.message)
    }
    console.log("Connected to admin database")    
})

// async function openDB() {
//   const db = await sqlite.open('/services/Admin/admin.db', { Promise })
//   const sql = 'CREATE TABLE IF NOT EXISTS Admin(id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, pass TEXT);'
//   await db.run(sql)
// }

router.get('/admin/login', (req, res) => {
    // const result = db.get('Select * from user', (err, results) => {
    //   console.log(results)
    //   // res.render(results)
    // })
    // console.log("Here is the result " + result)
    // console.log(req.body)
  })
  
router.post('/admin/register', (req, res) => {
  const username = req.body.username
  const password = req.body.password
  console.log(username)
  console.log(password)
  const result = db.get('SELECT * FROM admin', (err, results) => {
    if(err) {
      console.log(err)
    } else {
      console.log(results)
    }
  })
})
  
router.post('/admin/user', (req, res) => {
    console.log(req.body)
})


module.exports = router
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!