What databases can node use?

青灯夜游
Release: 2022-03-22 16:39:28
Original
3842 people have browsed it

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.

What databases can node use?

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

    • ##Hive

    • Redis

    • CouchDB

    • Other NoSQL implementations

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 driver

Use Taobao’s customized cnpm command to install:

$ cnpm install mysql
Copy after login

2. Connect to the database

In the following example, modify the database user name, password and database name according to your actual configuration:

test.js file code:

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);
});
Copy after login

The output result of executing the following command is:

$ node test.js
The solution is: 2
Copy after login

Database connection parameter description:

##Parameter host User Password port database charset LocalAddress socketPath timezone connectTimeout StringifyObjects TypeCast queryFormat SupportBigNumbers BigNumberStringsdateStrings debug MultipleStatementsflags sslFor more node-related knowledge, please visit:
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
nodejs tutorial

!

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!