koa--installation of the next generation Web development framework based on the node. JS Platform

Source: Internet
Author: User

KOA was created by Express's original squad and is committed to becoming a smaller, more expressive, and robust WEB framework. Writing Web applications using KOA, by combining different generator, eliminates the duplication of tedious callback function nesting and greatly improves the efficiency of error handling. KOA does not bind any middleware in the kernel method, it simply provides a lightweight and elegant library of functions, making it handy to write WEB applications.

Note: KOA is a next-generation Web development framework based on the node. JS platform, so the installation assumes that node. JS is installed

The installation steps are as follows:

1. Create a new folder Koadata

2. Open CMD,CD to the current new folder Koadata

3. Input in cmd: npm install KOA

(warning can be ignored, Koadata folder will appear Node_modules folder and Package-lock.json after installation)

4. Create a new service.js in the folder Koadata

5. Start editing the Service.js

The code is as follows:

Const Koa=require ("KOA");//define constants, introduce KOA framework
var service=new KOA ();//define KOA Object
Service.use (function * () {

this.body= "Hello word";
})
Service.listen (8089);//Set port number

6. Start the service in CMD
Node Service.js
(Note: Where Service.js is the newly created file in the folder Koadata)

7. Access in the browser: http://localhost:8089/
At this point the page will appear Hello Word, the initial test is generally successful, followed by the database part

8, open Phpstudy (because most of the data to be obtained, usually use the database to store data, so here still need to use phpstudy)
Then create a new database and table, add information, and later use

9. Use cmd
NPM I Koa-mysql

10. Edit Service.js

The code is as follows:

Const Koa=require ("KOA");
var service=new KOA ();
Const Mysql=require ("Koa-mysql");//introduced Koa-mysql
var Db=mysql.createpool ({host: "localhost", User: "Root", Password: "Root", Database: "Koadata"});// LocalHost is the database connection you want to access, Koadata is the database you want to access
Service.use (function * () {
var data=yield db.query ("SELECT * from user")//user is the table you want to query
This.body=data;
})
Service.listen (8089);

11. Restart data with cmd
Node Service.js

12. Access in the browser: http://localhost:8089/
The page will show you the data you want to access, as to how to use, to see everyone's personal thoughts

koa--installation of the next generation Web development framework based on the node. JS Platform

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.