Simple front-end separation User Login system based on native Js+node.js+mysql

Source: Internet
Author: User

First, login page

This is nothing to say, just put two pictures

Second, server-side

Use Express (document) to build a server, data pants with MySQL (basic statement), create a new users, and then create a new users table, we use this table.

The main server is to write a simple interface to handle the page sent over the request.

//Introducing DependenciesvarExpress = require (' Express ');varurl = require (' URL '));varBodyparser = require (' Body-parser '));varApp =Express ();
//Core Logic module varsql = require ('./login.js ')); App.use (bodyparser.urlencoded ({extended:true}));//Setting the response headerApp.all (' * ',function(req, res, next) {Res.header ("Access-control-allow-origin", "*"); Res.header ("Access-control-allow-methods", "Put,post,get,delete,options"); Res.header (' Access-control-allow-headers ', ' X-requested-with,content-type,access-control-allow-origin '); Res.header ("X-powered-by", ' 3.2.1 ') Res.header ("Content-type", "Application/json;charset=utf-8"); Next ();});//Exposed InterfaceApp.post ('/user ',function(req, res) {varquery = Url.parse (Req.url,true). Query; Switch(query.ctr) { Case' Add ': Sql.catchres ({type:' INSERT ', data:req.body},function(msg) {res.send (msg); }); Break; Case' Update ': Sql.catchres ({type:' UPDATE ', data:req.body},function(msg) {res.send (msg); }); Break; Case' Delete ': Sql.catchres ({type:' DELETE ', data:req.body},function(msg) {res.send (msg); }); Break; Case' Login ': Sql.catchres ({type:' SELECT ', data:req.body},function(msg) {res.send (msg); }); Break; default: Res.send (' Undefined contrl! '); } });//Listening PortApp.listen (' 8080 ',function() {Console.log (' Listen at 8080 ')})

Third, the operation
Node App.js

Our server starts up, listens on port 8080, and we initiate a request to port 8080:

original code in my GitHub warehouse, welcome to download:https://github.com/lastnigtic/node-login

Simple front-end separation User Login system based on native Js+node.js+mysql

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.