koa2 入門教程

koa

koa 中文
koa-generator

簡(jiǎn)介

koa 是一個(gè)新的 web 框架, 由 express 原班人馬打造,支持了 async 函數(shù)。

安裝 koa

該方式一般用于測(cè)試使用,正式的項(xiàng)目搭建常選擇用 skeleton。

npm i koa

安裝骨架(skeleton)生成器

npm i -g koa-generator

創(chuàng)建一個(gè)應(yīng)用

koa2 first-koa

注意 koa 與 koa2 是兩個(gè)不同的命令,使用 koa 會(huì)創(chuàng)建 koa1 骨架項(xiàng)目。koa1 與 koa2 最大的區(qū)別就是 koa1 使用 generator,而 koa2 使用 async/await。

輸出

bei@bei-pc:~/Code/JavaScript/guide/01-javascript/node/koa$ koa2 koa2-first

   create : koa2-first
   create : koa2-first/package.json
   create : koa2-first/app.js
   create : koa2-first/public
   create : koa2-first/public/javascripts
   create : koa2-first/public/images
   create : koa2-first/public/stylesheets
   create : koa2-first/public/stylesheets/style.css
   create : koa2-first/routes
   create : koa2-first/routes/index.js
   create : koa2-first/routes/users.js
   create : koa2-first/views
   create : koa2-first/views/index.pug
   create : koa2-first/views/layout.pug
   create : koa2-first/views/error.pug
   create : koa2-first/bin
   create : koa2-first/bin/www

   install dependencies:
     $ cd koa2-first && npm install

   run the app:
     $ DEBUG=koa2-first:* npm start

安裝依賴&執(zhí)行

npm i
npm start

看到這里就表示成功執(zhí)行了 koa 應(yīng)用,訪問 http://localhost:3000 即可查看。

bei@bei-pc:~/Code/JavaScript/guide/01-javascript/node/koa/first-koa$ npm start

> first-koa@0.1.0 start /home/bei/Code/JavaScript/guide/01-javascript/node/koa/first-koa
> node bin/www
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容