The databases that node can use are: 1. IBM DB2; 2. MS SQL Server; 3. PostgreSQL; 4. MySQL; 5. SQLite; 6. Oracle; 7. Mongo; 8. Hive; 9. Redis;10, CouchDB, etc.
The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, DELL G3 computer.
node.js is a development platform that allows JavaScript to run on the server side, which can be used to easily build network applications with fast response speed and easy expansion. Node uses an event-driven, non-blocking I/O model to be lightweight and efficient, making it ideal for running data-intensive real-time applications on distributed devices.
node.js supports the following Database:
IBM DB2
MS SQL Server
PostgreSQL
MySQL
SQLite
Oracle
NoSQL and Key/Value
Mongo
So How to choose?
What node uses as the database depends on the business scenario. All mainstream databases can be selected. Generally, mysql is used more in the industry. nodejs Oracle has many pitfalls, but it can be done. nodejs Mysql is used by the most people. After all, mysql is already very popular. nodejs mongodb fast fast = very fast, suitable for ultra-rapid development mode.Example: Node.js connects to MySQL database
1. Install the driverUse Taobao’s customized cnpm command to install:$ cnpm install mysql
var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '123456', database : 'test' }); 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); });
$ node test.js The solution is: 2
Description | |
---|---|
Host address (default: localhost) | |
Username | |
Password | |
Port number (default: 3306) | |
Database name | |
Connection character set (default: 'UTF8_GENERAL_CI', note that the letters in the character set must be capitalized) | |
This IP is used for TCP connection (optional) | |
Connect to the unix domain path, Ignored when using host and port | |
Time zone (default: 'local') | |
Connection timeout (default: no limit; unit: milliseconds) | |
Whether to serialize objects | |
Whether to convert column values into local JavaScript type values (default: true) | |
Custom query statement formatting method | |
When the database supports bigint or decimal type columns, you need to set this option to true (default: false) | |
supportBigNumbers and bigNumberStrings enable forcing bigint or decimal columns to be returned as JavaScript string types (default: false) | |
Force timestamp, The datetime and data types are returned as string types instead of JavaScript Date types (default: false) | |
Enable debugging (default: false) | |
Whether to allow multiple MySQL statements in a query (default: false) | |
Use To modify the connection flag | |
Use the ssl parameter (the same format as the crypto.createCredenitals parameter) or a string containing the ssl profile name. Currently only bundled with Amazon RDS configuration file |
The above is the detailed content of What databases can node use?. For more information, please follow other related articles on the PHP Chinese website!