Npm:
The full name of NPM is the node Package Manager, which resembles Ruby's Gem,python pypl, setuptools,php pear, which is the packet manager in Nodejs. The Nodejs itself provides the basic modules. However, the development of practical applications on these basic modules requires more work. There are already nearly thousands of nodejs libraries or frameworks on NPM that can help nodejs developers with more complex applications in every way.
Install NPM (under Unix):
Installing node modules with NPM
such as MySQL:
NPM install MySQL
Connect MySQL database with node, and add and revise, directly paste code.
var mysql = require (' mysql '); var conn = Mysql.createconnection ({host: ' localhost ', User: ' Root ', password: ' Root ', database: ' Nodedb ', port:8889}); Conn.connect (); Console.log ("Connect Mysql Success"); var selectsql = ' SELECT * fro M USERTB '; var insertsql = ' INSERT INTO USERTB values ("Conan"), ("fens.me") '; var deletesql = ' Delete from T_user '; var update SQL = ' Update t_user set name= ' Conan Update ' where name= ' Conan ';//selectconn.query (Selectsql, function (err, rows) {if (err) Console.log (err); Console.log ("Select ==>"); for (var i in rows) {Console.log (rows[i]); }});////insert//Conn.query (Insertsql, function (ERR1, res1) {//if (ERR1) Console.log (ERR1);//Console.log ("Insert Return ==> ");//Console.log (RES1);//});////delete//Conn.query (Deletesql, function (ERR2, res2) {//if (err 2) Console.log (ERR2);//Console.log ("DELETE Return ==>");//Console.log (RES2);/});////update//Conn.query (U Pdatesql, function (ERR3, RES3) {// if (ERR3) Console.log (ERR3);//Console.log ("UPDATE Return ==>");//Console.log (RES3);/}); Conn.end ();
Node connects to MySQL and makes additional deletions and checks