Get Started Nodejs

Source: Internet
Author: User

Simple login and Change password operation.

Detailed description of the change process

1. First find the data SQL function to be used in the database

BEGIN
DECLARE isin int default (0);
#Routine body goes here ...
Select COUNT (*) into Isin from Ufa_user where account= userName and password= pwd;
If Isin>0 Then
Update ufa_user Set password = pwd1 where account = UserName;
ELSE
select-1;
End If;

END

2. Need two JS, one request, one corresponding.

Server.js Register.js

Important!

2.1 Register needs to link-------------JS, which is local, runs in node environment.

var mysql = require (' mysql2 ');
function Initpool (db) {
return Mysql.createpool ({
host: ' 123.56.179.219 ',
port:3306,
User: ' Root ',
password: ' Yangxiao ',
Database:db,
charset: ' Utf8_unicode_ci ',
Debug:false,
connectionlimit:10
});
}
var mysqlhm =new Map ();
function Initconn (dbname) {
var db = Mysqlhm.get (dbname);
if (!db) {
db = Initpool (dbname);
Mysqlhm.set (dbname,db);
}
return db;
}
String.prototype.format = function ()
{
var args = arguments;
return This.replace (/\{(\d+) \}/g,
function (m,i) {
return args[i];
});
}
/****************************************************/
exports.callmysql=function (DBNAME,QUERY,CB) {
Initconn (dbname). getconnection (function (err,connection) {
if (err) Console.log (err)
console.log (query)
if (connection) {
connection.query (query,function (err,rows,fields) {
if (err) Console.log (err)
try{
CB (rows);
}catch (e) {
CB ([]);
}
connection.release ();
});
}else{
CB ([]);
}
});
};

The link is connected with JS syntax
2.2 Response Process ~ ~
var util = require (".. /util.js ");
Module.exports = function () {


}
2.3 Request Process ~ ~
Defining variables + selecting interfaces

3 Front-End request process

Attention! Contenttxpe must be demanded in Ajax,
ContentType: "Application/json";
A specified port that the URL writes itself, that is, a function in the response function;

Data objects defined previously by Ajax are the PWD in this article
Data:stringify (PWD);
After that, the front end is available for data manipulation.
In Webstrom, you can see the results of node operation and the cause of the error. Equivalent to Dos

Write more complicated tomorrow, and then share it seven o'clock tomorrow night.



Get Started Nodejs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.