1.ECMA & JS & Node.js

NPM I lodash --save // Install lodashCopy the code
  • NPM init initialization => Change the startup page to app.js => Node app.js run

2. HTTP & GET POST processing (HTTP-test)

2.1 Processing GET Requests

  • By default, the browser also sends a request for the icon in the upper left corner

2.2 Processing POST Requests

  • Define a postData to hold incoming data in the data stream
  • Chunk is a binary format that requires toString conversion
  • The server receives data through data stream, and the flowing data triggers data in ON for several times. The end triggers on in end, and has been listening

2.3 Comprehensive Example

  • Text/HTML is also a string; application/json simply specifies that the string is in JSON format

3. Develop routes

3.1 Setting up the development environment

yarn add nodemon cross-env --save-dev
Copy the code

  • Install two dependencies, set dev, run bin/www.js through nodemon, instead of Node directly run, can run in real time, cross-env set environment variable is dev, compatible with Linux and Windows environment, development environment dev
  • Run through NPM run dev
yarn run dev
Copy the code

  • App.js is related to the service, and www.js is the basic configuration, so split

3.2 Initializing routes