nvm install 7 cnpm install koa # 編輯 my-koa-app.js 文件 , 寫入代碼 node my-koa-app.js
nvm install 7
cnpm install koa
# 編輯 my-koa-app.js 文件 , 寫入代碼
node my-koa-app.js
$ node first.js module.js:538 throw err; ^ Error: Cannot find module 'koa' at Function.Module._resolveFilename (module.js:536:15) at Function.Module._load (module.js:466:25) at Module.require (module.js:579:17) at require (internal/module.js:11:18) at Object.<anonymous> (E:\Koa\first.js:1:75) at Module._compile (module.js:635:30) at Object.Module._extensions..js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) at Function.Module._load (module.js:489:3)
x
$ node first.js
module.js:538
throw err;
^
Error: Cannot find module 'koa'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (E:\Koa\first.js:1:75)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
cnpm i -g koa Downloading koa to C:\Users\pc\AppData\Roaming\npm\node_modules\koa_tmp Copying C:\Users\pc\AppData\Roaming\npm\node_modules\koa_tmp\_koa@2.4.1@koa to C:\Users\pc\AppData\Roaming\npm\node_modules\koa Installing koa's dependencies to C:\Users\pc\AppData\Roaming\npm\node_modules\koa/node_modules [1/24] content-disposition@~0.5.0 installed at node_modules\_content-disposition@0.5.2@content-disposition [2/24] escape-html@~1.0.1 installed at node_modules\_escape-html@1.0.3@escape-html [3/24] depd@^1.1.0 installed at node_modules\_depd@1.1.1@depd [4/24] error-inject@~1.0.0 installed at node_modules\_error-inject@1.0.0@error-inject [5/24] delegates@^1.0.0 installed at node_modules\_delegates@1.0.0@delegates [6/24] content-type@^1.0.0 installed at node_modules\_content-type@1.0.4@content-type [7/24] cookies@~0.7.0 installed at node_modules\_cookies@0.7.1@cookies [8/24] fresh@^0.5.2 installed at node_modules\_fresh@0.5.2@fresh [9/24] debug@* installed at node_modules\_debug@3.1.0@debug [10/24] destroy@^1.0.3 installed at node_modules\_destroy@1.0.4@destroy [11/24] koa-compose@^4.0.0 installed at node_modules\_koa-compose@4.0.0@koa-compose [12/24] mime-types@^2.0.7 existed at node_modules\_mime-types@2.1.17@mime-types [13/24] statuses@^1.2.0 existed at node_modules\_statuses@1.4.0@statuses [14/24] koa-is-json@^1.0.0 installed at node_modules\_koa-is-json@1.0.0@koa-is-json [15/24] http-errors@^1.2.8 installed at node_modules\_http-errors@1.6.2@http-errors [16/24] http-assert@^1.1.0 installed at node_modules\_http-assert@1.3.0@http-assert [17/24] parseurl@^1.3.0 installed at node_modules\_parseurl@1.3.2@parseurl [18/24] only@0.0.2 installed at node_modules\_only@0.0.2@only [19/24] vary@^1.0.0 installed at node_modules\_vary@1.1.2@vary [20/24] on-finished@^2.1.0 installed at node_modules\_on-finished@2.3.0@on-finished [21/24] accepts@^1.2.2 installed at node_modules\_accepts@1.3.4@accepts [22/24] koa-convert@^1.2.0 installed at node_modules\_koa-convert@1.2.0@koa-convert [23/24] type-is@^1.5.5 installed at node_modules\_type-is@1.6.15@type-is [24/24] is-generator-function@^1.0.3 installed at node_modules\_is-generator-function@1.0.6@is-generator-function All packages installed (36 packages installed from npm registry, used 2s, speed 206.78kB/s, json 35(43.75kB), tarball 347.06kB)
x
cnpm i -g koa
Downloading koa to C:\Users\pc\AppData\Roaming\npm\node_modules\koa_tmp
Copying C:\Users\pc\AppData\Roaming\npm\node_modules\koa_tmp\_koa .4.1 to C:\Users\pc\AppData\Roaming\npm\node_modules\koa
Installing koa's dependencies to C:\Users\pc\AppData\Roaming\npm\node_modules\koa/node_modules
[1/24] content-disposition~0.5.0 installed at node_modules\_content-disposition .5.2-disposition
[2/24] escape-html~1.0.1 installed at node_modules\_escape-html .0.3-html
[3/24] depd^1.1.0 installed at node_modules\_depd .1.1
[4/24] error-inject~1.0.0 installed at node_modules\_error-inject .0.0-inject
[5/24] delegates^1.0.0 installed at node_modules\_delegates .0.0
[6/24] content-type^1.0.0 installed at node_modules\_content-type .0.4-type
[7/24] cookies~0.7.0 installed at node_modules\_cookies .7.1
[8/24] fresh^0.5.2 installed at node_modules\_fresh .5.2
[9/24] debug* installed at node_modules\_debug .1.0
[10/24] destroy^1.0.3 installed at node_modules\_destroy .0.4
[11/24] koa-compose^4.0.0 installed at node_modules\_koa-compose .0.0-compose
[12/24] mime-types^2.0.7 existed at node_modules\_mime-types .1.17-types
[13/24] statuses^1.2.0 existed at node_modules\_statuses .4.0
[14/24] koa-is-json^1.0.0 installed at node_modules\_koa-is-json .0.0-is-json
[15/24] http-errors^1.2.8 installed at node_modules\_http-errors .6.2-errors
[16/24] http-assert^1.1.0 installed at node_modules\_http-assert .3.0-assert
[17/24] parseurl^1.3.0 installed at node_modules\_parseurl .3.2
[18/24] only .0.2 installed at node_modules\_only .0.2
[19/24] vary^1.0.0 installed at node_modules\_vary .1.2
[20/24] on-finished^2.1.0 installed at node_modules\_on-finished .3.0-finished
[21/24] accepts^1.2.2 installed at node_modules\_accepts .3.4
[22/24] koa-convert^1.2.0 installed at node_modules\_koa-convert .2.0-convert
[23/24] type-is^1.5.5 installed at node_modules\_type-is .6.15-is
[24/24] is-generator-function^1.0.3 installed at node_modules\_is-generator-function .0.6-generator-function
All packages installed (36 packages installed from npm registry, used 2s, speed 206.78kB/s, json 35(43.75kB), tarball 347.06kB)
const Koa = require('koa'); const app = new Koa(); app.use(async ctx => { ctx.body = 'Hello World'; }); app.listen(3000);
const Koa = require('koa');
const app = new Koa();
app.use(async ctx => {
ctx.body = 'Hello World';
});
app.listen(3000);
把 const Koa = require('koa'); 換成 const Koa = require('C:/Users/pc/AppData/Roaming/npm/node_modules/koa'); 或 const Koa = require('C:\\Users\\pc\\AppData\\Roaming\\npm\\node_modules\\koa');
x
把
const Koa = require('koa');
換成
const Koa = require('C:/Users/pc/AppData/Roaming/npm/node_modules/koa');
或
const Koa = require('C:\\Users\\pc\\AppData\\Roaming\\npm\\node_modules\\koa');