HapiJS development manual and hapijs Manual
HapiJS development manualAuthor: chszs, reprinted with note. Blog homepage: http://blog.csdn.net/chszs
1. Introduction to HapiJS
HapiJS is an open-source, Node-based. the js application framework is suitable for building applications and services. Its design goal is to allow developers to focus on developing reusable application business logic, provide developers with the infrastructure required to build application business logic. The latest version of HapiJS is 7.2.0.
Ii. HapiJS installation and project configuration
1. Install the Hapi Library
The installation of HapiJS is simple. Execute the following command:
$ Sudo npm install hapi-g
Hapi@7.2.0/usr/local/lib/node_modules/hapi
── Cryptiles@2.0.4
── Heavy@1.0.0
── Topo@1.0.2
── Accept@1.0.0
── Items@1.1.0
── Kilt@1.1.1
── Catbox-memory@1.1.0
── Boom@2.5.1
── Qs@2.2.4
── Call@1.0.0
── Statehood@1.2.0
── H2o2@2.0.1
── Iron@2.1.2
── Shot@1.3.5
── Glue@1.0.0
── Wreck@5.0.1
── Hoek@2.8.0
── Catbox@4.0.3
── Vision@1.1.0
├ ── Mimos@1.0.0 (mime-db@1.1.1)
├ ── Rejoice@1.0.0 (bossy@1.0.2)
├ ── Inert@1.1.0 (lru-cache@2.5.0)
├ ── Joi@4.7.0 (isemail@1.1.1)
└ ── Subtext@1.0.1 (content@1.0.1, pez@1.0.0)
2. configuration items
1) create a new directory named myproject
$ Mkdir myproject
$ Cd myproject
2) run the initialization command in the directory
$ Npm init
This command generates the package. json file, which is the metadata of the project.
Run the following command:
$ Npm install -- save hapi
It installs the hapi library under the project and writes the hapi dependency to package. json.
At this point, everything required for project development is ready.
Iii. Development Instance
1. Create a server
// Server. js
Var Hapi = require ('hapi ');
Var server = new Hapi. Server (3000 );
Server. start (function (){
Console. log ('server running at: ', server.info. uri );
});
First, we need the Hapi library.
Next, we create a new hapi Server Object and pass the port number to be listened on to the server object.
Finally, the server object is started and the log information is output.
Note: When creating a server object, you can provide the host name, IP address, Unix socket file, or the pipe bound to the server name in Windows.
2. Start the server
Run the following command:
$ Node server. js
Access http: // 127.0.0.1: 3000/. The browser displays the following content:
{& Quot; statusCode & quot;: 404, & quot; error & quot;: & quot; Not Found & quot "}
Normally, because there is no content on the server itself, the routing logic is added below.
3. Routing Logic
// Server. js
Var Hapi = require ('hapi ');
Var server = new Hapi. Server (3000 );
Server. route ({
Method: 'get ',
Path :'/',
Handler: function (request, reply ){
Reply ('hello, world! ');
}
});
Server. route ({
Method: 'get ',
Path: '/{name }',
Handler: function (request, reply ){
Reply ('hello, '+ encodeURIComponent (request. params. name) + "! ");
}
});
Server. start (function (){
Console. log ('server running at: ', server.info. uri );
});
Start the server again:
$ Node server. js
Visit http: // 127.0.0.1: 3000/. The browser displays the following content:
Hello, world!
Visit http: // 127.0.0.1: 3000/Zhang San. the browser displays the following content:
Hello, % E5 % BC % A0 % E4 % B8 % 89!
The routing logic runs normally.
Note:
The method parameter can be any valid HTTP method or asterisk ).
The path parameter defines the access path, which can contain parameters, optional parameters, and even wildcards.
Iv. Use plug-ins
When creating a Web application, we usually need access logs. To add basic log output to an application, we can load the good plug-in on the server.
1. Install the good plug-in
$ Sudo npm install -- save good
Good@3.1.1 node_modules/good
── Json-stringify-safe@5.0.0
── Good-reporter@2.0.0
── Async@0.9.0
── Hoek@2.8.1
── Moment@2.8.3
├ ── Good-file@2.0.0 (items@1.1.0)
└ ── Joi@4.7.0 (topo@1.0.2, isemail@1.1.1)
2. Update the server. js code.
// Server. js
Var Hapi = require ('hapi ');
Var Good = require ('good ');
Var server = new Hapi. Server (3000 );
Server. route ({
Method: 'get ',
Path :'/',
Handler: function (request, reply ){
Reply ('hello, world! ');
}
});
Server. route ({
Method: 'get ',
Path: '/{name }',
Handler: function (request, reply ){
Reply ('hello, '+ encodeURIComponent (request. params. name) + "! ");
}
});
Server. pack. register (Good, function (err ){
If (err ){
// Something bad happened loading the plugin
Throw err;
}
Server. start (function (){
Server. log ('info', 'server running at: '+ server.info. uri );
});
});
Run server. js and the console outputs:
141102/161007. 644, info, Server running at: http: // localhost: 3000
If we continue to access: http: // 127.0.0.1: 3000/liqiang
And http: // 127.0.0.1: 3000/
The console will continue to output:
141102/161150. 689, request, http: // Thinker-SCSI: 3000: get/liqiang {} 200 (37 ms)
141102/161155. 812, request, http: // Thinker-SCSI: 3000: get/{} 200 (4 ms)
Software Development Manual
What did you use for development? Generally, if the code comments are clearly written during development, the user manual will be generated by yourself, such as java
I have contact information in Baidu hi. You can consult me for details. My company has been engaged in software development for a long time.
How to compile a development manual? We have a template! Now!
1 Introduction
1.1 Purpose: to clarify the purpose of writing a requirement manual and specify the target audience.
1.2 Project Background: it should include
● The entrusting unit, happy unit and competent department of the project;
● Relationship between the software system and other systems.
1.3 definition: lists the definitions of specialized terms used in the document and the acronyms.
1.4 references: may include
● Approved plans and tasks, contracts or approvals from higher authorities
● Documents Reference Materials and specifications
● List the author, title, number, publication date, publisher or source of the materials
2 task Overview
2.1 goals
2.2 Runtime Environment
2.3 conditions and restrictions
3. Data Description
3.1 Statement data
3.2 dynamic data: Includes input data and output data.
3.3 database Description: name and type of the database to be used.
3.4 Data Dictionary
3.5 data collection
4. Functional Requirements
4.1 function division
4.2 Function Description
5. Performance Requirements
5.1 data accuracy
5.2 time features: such as response time, update processing time, data conversion and transmission time, and running time.
5.3 Adaptability: the ability to adapt to changes in operation modes, runtime environments, interfaces with other software, and development plans.
6. operation requirements
6.1 User Interface: such as screen format, report format, menu format, input and output time.
6.2 hardware interface
6.3 Software Interface
6.4 troubleshooting
7. Other requirements
Such as usability, security and confidentiality, maintainability, and portability.