nodejs

The teacher. What is the difference between Express and KOA? A few of my friends use Express all the time

Want to learn Node well, master the native module situation

The biggest feature of Node is asynchro, with await and async forced into synchronization, feeling monstrous

Does the next update support async await? I think they wrote something, or they made a promise


Multithreaded – Java CPU single thread – JS synchronous blocking asynchronous non-blocking

Compute-intensive IO intensive


Nodejs: 1. Nodejs is javascript 2. positioning

          nodejs        java
Copy the code

Simple and convenient √ × Safe × √

The middle layer


1. Middle layer (Api services, microservices) 2. Tools


Nodejs: 1. Native 2. Koa 3.


Module 1. System module 2. Custom module import module — no path system, node_modules with path to the specified path *.. /.. /.. /.. /.. / libs/main/catalog/mod. Js 3. NPM third-party modules

NPM install -g CNPM — registry.npm.taobao.org CNPM I koa

yarn npm install -g yarn yarn add koa

I. Initialize yarn init [-y] ii. Install yarn add XXX xx XX xx… Iii. Install dependencies on YARN from package iv. Run the yarn run script name * YARN Run start -> yarn start


Koa – async and await

Koa 1 generator *+yield KOa 2 transition KOa 3 async/await


Const koa =require(‘koa’);

let app=new Koa();

app.use(async ctx=>{

});

app.listen(xxx);


CTX. Body = XXX;

Status Status code CTx. status=302;

Ctx.get (‘ name ‘); Ctx.set (‘ name ‘, ‘value ‘);


Koa Middleware:


/news /news/hot /news/caijing /news/guonei

/picture /picture/fentjing /picture/renwu


www.xxxx.com/news/184536… www.xxxx.com/news/984537…