I want to display some db query result on my website Using browserify to include node modules on client side I get the error mentioned above and am stuck now:
This is my main.js
const mysql = require('promise-mysql')
async function run() {
try {
const connection = await mysql.createConnection({
host: '127.0.0.1',
user: 'root',
password: '',
database: 'testdb',
port: 3306
})
const result = await connection.query(
'SELECT something FROM table1;'
)
await connection.end()
return JSON.stringify(result);
} catch (e) {
console.error(e)
}
}
run().then(data => {
document.getElementById('response').innerHTML = data;
console.log(data);
});
And this is my test websites body: (I created the bundle.js file via $ watchify testdb_work.js -o bundle2.js -v)
<body>
<div class="container">
<h2>Welcome to the Client Side.</h2>
<div class="well">
<div id="response">
</div>
</div>
</div>
<script src="main.js"></script>
<script src="bundle.js"></script>
</body>
Here is a link to the bundle.js (it is really huge): bundel.js
I am working on macOS 10.13