2.node. Framework express

By node. js js development from the browser program, the main tool for live servers, such as file handling.

With the most popular and stable framework node, express.

1. Accept a project, the first step look at the packge. Inside look at the dependencies of dependencies. Install it with yarn install

2. If you do not add it with yarn add (dependent on) the package inside it (use the same terminal in the package directory)

3. The main function of project implementation

IF     (require.main === Module) { 
main () 
} 
// If executed directly, you can perform a function inside 
// invoked when files are executed because of the introduction of that document, then the judge can avoid references

4. Run the project when the display port is occupied // restart the computer, change a port

The server program. Back to the main page, to provide the distal end ajax api with (communication, using backend // Resolution Protocol)

http protocol is actually a string

json. stringify (data, nul, 2) there is a character string such parsed indented

Modify index.html file restart is not required, modify the need to restart the project file demo.js

To get the request to return the front. body need to install a library body - parser

app.use (bodyParser.json ()) to the front end of a data format sent automatically resolve json

Guess you like

Origin www.cnblogs.com/-constructor/p/11810611.html