NODEJS+EXTJS+MONGODB Development Third Day login page (1)

Source: Internet
Author: User

The quickest way to learn new technology is to do the project. After the first day of the environment was set up, I was ready to build a Web system based on Nodejs+extjs+mongodb.


Environment Construction: http://blog.csdn.net/jrainbow/article/details/38845639

First, the reason for the choice of technology

1, Nodejs. Needless to say, this is to learn this. Because it's a web system, I chose the express framework.


2, ExtJS. The reason is also very simple, because the author does not work, and has been used before the EXTJS framework. In order to be more satisfied with their own silver bullet mentality, the project chose a desktop framework based on the extjs4.x version.


3, Mongodb. It is easy to build and use. Compared to the author's previous use of Hbase,mongodb dependency is much lower. MongoDB Direct download back decompression can be used.

MongoDB Simple to use: http://blog.csdn.net/jrainbow/article/details/39163843


Second, login page and function realization

1, according to the content of the first day to create a PCRM system.


The directory is as follows:












Bin, which holds the default startup script doc, is  deposited into the project's document modules, which is  used to store the data model. Similar to the combination of entity and DAO in Java EE development. Of course, you can also split into modules and Daos two directory node_modules, storing all the project dependencies. Similar to the jar package directory in Java. Public   , static file (css,js,img). I also put the page's JavaScript file in this directory. Routes, the routing file (C,controller in MVC). Equivalent to the combination of controller and service in Java EE development. Of course, it can also be opened here. Views, page files (ejs templates). Equivalent to HTML or JSP pages. Package.json, the project relies on configuration and developer information. Equivalent to MAVEN's coordinate configuration file. App.js, program startup file  

2, the login page in the Views directory to create a Ejs page file Login.ejs.
<! DOCTYPE html><!--[if LT IE 7]> 
Put the login page CSS file login.css into the Public/stylesheets directory







3, in the background receive page delivery information in the routes directory to create a route file login.js.


var express = require (' Express '); var router = Express. Router ();/* GET home page. */router.get ('/', function (req, res) {    res.render (' login ');}); Router.get ('/check ', function (req, res) {
    Console.log (Req.query.username); Console.log (Req.query.password);}); Module.exports = router;

Simply explain this controller:
For more convenient use of HTTP to process data. We use the Express framework in our projects.
As with Java development, to use a class, we need to import this class first. Nodejs is using require to load the Express module in.
We then use the Router object to get the page request. There are a number of ways router receive pages, and we use get here. The use of the Get method rather than the rest is based on the requirements of the RESTful specification. It will be mentioned in the later use.
The first get method is to forward a non-default request to the login page. The second get method is to receive the "/check" request in the login page action. and output the user name and password.
Module.exports = Router; release our controller as a module for use in other modules.


4. Release the Router

In the App.js file, import the login routing module first in the file header

var login = require ('./routes/login ');


To set the access path for the login route

App.use ('/', login); App.use ('/main ', main);

If you are using Express to build the project, a main route is generated by default, and the path of the path is the primary path. Here I modify the route for the master path to login, and the main path is the/main path.


5, start the service start the server, Access address: http://127.0.0.1:3000/


















Enter user name and password: admin + Test


Background Terminal display:








Our page data and the background of the HTTP channel has been opened. Tomorrow we're going to write the logic for the login checksum.


NODEJS+EXTJS+MONGODB Development Third Day login page (1)

Related Article

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.