Recently this period of time to study node feel good, I did a delete and change, although some simple, but thought is figured, in fact, all items are deleted and modified to help beginners quickly grasp node
First of all
This example is based on Node+express+node-mysql rapid build a set of additions and deletions, the view template is Jade, is basically now usable to the technology, the market instance is particularly small, useful and not new, so write a
Basic work
First we prepare some basic, because I am using MySQL trouble can be installed on their own MySQL, to the official website can be under various operating system installation package.
The example is a table, and here is the table statement
SET NAMES UTF8;
SET foreign_key_checks = 0
-- ----------------------------
--Table structure for ' user '
-- ----------------------------
DROP TABLE IF EXISTS ' user ';
CREATE TABLE ' user ' (
' id ' int (one) not NULL auto_increment,
' username ' varchar (255) DEFAULT NULL,
' Password ' varchar (255) DEFAULT NULL,
' Age ' int (4) DEFAULT NULL,
' Info ' varchar (255) DEFAULT NULL,
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=15 DEFAULT Charset=utf8;
SET foreign_key_checks = 1;
Go to git and download my project
NPM Install the project required kit, the following configuration of the database connection, the configuration of the database connection in node is quite simple, just need the following code, not like in Java Import jar package and then write a set of connection management class, it can be broken the heart of people
1 var mysql = require ("MySQL"); 2
3 var connection = Mysql.createconnection ({
4 host: ' localhost ',
5 User: ' Root ',
6 Password: ' 81527319 ',
7 database: ' Node_test '
8});
Here host is the current IP address of your computer, user is the username, password is the password, database is to operate databases, if to this step, then you can open the server to try and add and change the
Structure of the project (helps to quickly understand the project)
-action the Ajax interface used by the server to provide to the client browser
-mysqldb.js used to provide User.js with a linked database of the tool class and the actual operation of the database class
-user.js is used to provide the implementation layer about the user's additions and deletions to the method equivalent to a middle layer
-node_modules is a dependency package that Nodejs needs to use
-public provides front-desk CSS and JS
-routes provides routing
-views providing a view template
-app.js Start and entry of the program
Other places I have to make simple comments that everyone convenient to watch
The same project package has the relevant node of the source code and a blog case source of course I did not refer to the blog source code to achieve my program, the basic is this, I wish you good luck
Node+express+node-mysql actual combat in a full set of MySQL (add-and-revise search)