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
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;
SETForeign_key_checks= 0
-- ----------------------------
--Table structure for ' user '
-- ----------------------------
DROPTABLEIFEXISTS`User`;
CREATETABLE`User` (
' ID 'int( One) notNULLAuto_increment,
' Username 'varchar(255)DEFAULTNULL,
' Password 'varchar(255)DEFAULTNULL,
' Age 'int(4)DEFAULTNULL,
' Info 'varchar(255)DEFAULT NULL,
PRIMARYKEY(' ID ')
) ENGINE=InnoDB auto_increment= theDEFAULTCHARSET=UTF8;
SETForeign_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 varMySQL = require ("MySQL");2
3varConnection = Mysql.createconnection ({
4Host: ' localhost ',
5User: ' Root ',
6Password: ' 81527319 ',
7Database: ' 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
Welcome to my git to steal the source code, click Repositories to view node
Https://github.com/Mrxdh
If you like, you can help. Click Follower
If you have any help, please help me to recommend!
Node+express+node-mysql actual combat in a full set of MySQL (add-and-revise search)