Tuesday 24 March 2020

need help sqlite3 module

Hello guys im sure this question has been ask somewhere already but i couldn't find it, i have search the internet for days to the point that im thinking about giving up nodejs (don't get me wrong i like node but it is just frustrating not knowing what to do).My problem is getting data from database in a file.js i have:const sqlite3 = require('sqlite3')const db = sqlite3.Database('pathToDB', (err) => {//connection successful})​const getUser = (username) => {db.get('select from table where username = $username', {$username: username}, (err, result) => {if (err) return err.messageconsole.log(result) //it logs the result ok but it wont return result to the function calling getUserreturn result})​and im calling get user from another file containing a endpoint using expressendpoint { //expressjs endpointconsole.log(getUser('username')) //returns undefined}if somebody can please help me make it that when i call getUser it returns result please thanks im just starting to learn node btw

Submitted March 25, 2020 at 05:01AM by el-calde

No comments:

Post a Comment