mysql
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
bignumber.js | 9.0.0 | 99.16 kB | MIT | prod | |
readable-stream | 2.3.7 | 25.09 kB | MIT | prod | |
safe-buffer | 5.1.2 | 9.59 kB | MIT | prod | |
sqlstring | 2.3.1 | 6.18 kB | MIT | prod |
MySQL is a Node.js driver written in JavaScript for MySQL database. MySQL driver does not require compiling and comes with 100% MIT license. The driver enables your Node.js applications to communicate with MySQL database, execute queries, handle responses, and perform CRUD operations.
To use MySQL in Node.js, you firstly need to install the package using npm:
$ npm install mysql
Then in your Node.js script, require the MySQL package, create a connection using your database's credentials, and execute queries using the connection object.
Here is an example of how to use it:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
connection.end();
In the above code, mysql.createConnection
is used to establish connection to MySQL. SQL queries are executed in sequence and not parallel. The connection.connect
method is used to establish connection and connection.end
is used to close the connection.
The documentation for MySQL in Node.js can be found on the GitHub repository. The readme file of the repository itself provides extensive documentation covering installation, usage, API references, and other useful details. For more advanced topics, you can check out the issues and pull requests in the repository.
You can access the documentation at: https://github.com/mysqljs/mysql