node.js - How to make a request in a localhost mysql database -
i using mysql , request. want make request in localhost server. need know how make request localhost server because don't understand how, i'm running continuous loop.
var connection = mysql.createconnection({ host: 'localhost', user: 'root', password: '', database: 'virtual_currency_price' }); request:
router.get('/getprice', function(req, res){ request(connection, function (error, response, body) { if (!error && response.statuscode == 200){ } }); }); i'm trying figure out how i'm failing miserably
the table i'm trying called "price" , using datetime fetch prices.
after establish connection server can use fetch data database. don't need make request using module, use connection directly execute queries below:
var mysql = require('mysql'); var connection = mysql.createconnection({ host : 'localhost', user : 'root', password : '', database : 'virtual_currency_price' }); connection.connect(); connection.query('select * price', function(err, rows, fields) { if (err) throw err; console.log(rows); }); connection.end(); it's recommended create pool of connections instead , reuse them in app instead of creating every time need access db.
see docs github.
Comments
Post a Comment