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