zoukankan      html  css  js  c++  java
  • 【One by one系列】一步步学习node.js的web框架Koa

    Koa快速入门

    新建项目

    mkdir koa-quick-start

    cd koa-quick-start

    npm init -yes

    可以看到koa-quick-start下面有package.json

    {
      "name": "koa-quick-start",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo "Error: no test specified" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC"
      }
    

    下载koa包

    npm install koa

    再看package.json

    {
      "name": "koa-quick-start",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo "Error: no test specified" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "dependencies": {
        "koa": "^2.11.0"
      }
    }
    
    

    没错,多了koa的依赖

    并且还多了node_modules文件夹

    Hello Koa

    新建文件index.js

    键入如下代码

    const Koa =require('koa');
    const app=new Koa();
    
    app.use(async (ctx, next) => {
        await next()
        ctx.response.type = 'text/html'
        ctx.response.body = '<h1>Hello World</h1>'
    });
    
    console.log("koa start,listen 3000...");
    app.listen(3000);
    

    运行起来

    node index.js

    koa start,listen 3000...

  • 相关阅读:
    ISC2016训练赛 phrackCTF--Classical CrackMe
    JCTF 2014 小菜一碟
    攻防世界--ReverseMe-120
    lstm torch
    pandas 处理 纽约签到数据集
    python datatime
    tf.keras 模型 多个输入 tf.data.Dataset
    python **kwarg和*args
    java 优先队列 大根堆
    python总结
  • 原文地址:https://www.cnblogs.com/RandyField/p/12221094.html
Copyright © 2011-2022 走看看