To access a MySQL database with Node.js, you need a MySQL driver. This tutorial will use the "mysql" module, downloaded from NPM. To download and install the "mysql" module, open the Command Terminal and execute the following: C:\Users\Your Name>npm install mysql Now you have downloaded and installed a mysql database driver. Node.js can use this module to manipulate the MySQL database: var mysql = require('mysql'); Create ConnectionStart by creating a connection to the database. Use the username and password from your MySQL database. demo_db_connection.js var mysql = require('mysql'); var con = mysql.createConnection({ con.connect(function(err) { Save the code above in a file called "demo_db_connection.js" and run the file: Run "demo_db_connection.js" C:\Users\Your Name>node demo_db_connection.js Which will give you this result: Now you can start querying the database using SQL statements. Query a DatabaseUse SQL statements to read from (or write to) a MySQL database. This is also called "to query" the database. Untuk koneksi ke database MySQL cukup mudah seperti yang telah dibahas pada bab sebelumnya tentang Node dan Database MySQL.
Parsing argumen dilakukan oleh
Jika anda berada pada platform UNIX atau GNU LINUX script diatas bisa dirubah untuk
Kemudian untuk menjalankannya cukup mudah seperti berikut
Script Penulis sarankan untuk ke depannya jika diinginkan penulisan tanpa 0 JavaScript ES6. |