how to manage a db connection in javascript
//put these lines in a seperate file
const mysql = require('mysql2');
const connection = mysql.createPool({
host: "localhost",
user: "",
password: "",
database: ""
// here you can set connection limits and so on
});
module.exports = connection;
//put these on destination page
const connection = require('../util/connection');
async function getAll() {
const sql = "SELECT * FROM tableName";
const [rows] = await connection.promise().query(sql);
return rows;
}
exports.getAll = getAll;
Also in JavaScript:
- current month in javascript
- how to move an element of an array in javascript
- react tooltip on disabled button
- How to find the max id in an array of objects in JavaScript
- react form hook trigger is not a function
- insert js in html
- calculate average in javascript
- search bar in react js example
- href before onclick js
- Javascript get random item from array
- jquery preload images
- install nuxt js
- js convert truthy
- unix timestamp to date javascript yyyy-mm-dd
- elasticsearch aggregation unique values
- javascript filter array of objects by key
- async function fetchJson
- what is package.json in node
- checking if var is not defined js
- WHAT IS NODE IN DOM
- jQuery - Get Content and Attributes
- catch javascript
- [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
- map with async