1

npm パッケージを正常にインストールでき、「npm install Express」コマンドで Express をインストール済みです。これは、実行しようとしている app.js ファイルです。

/* app.js */
var app = require('express').createServer();

app.get('/', function(req, res){
    res.send('hello world');
});

app.listen(3000);

c:\> node app.js

これはエラーです:

node.js:63
    throw e;
    ^
Error: Cannot find module 'express'
    at loadModule (node.js:275:15)
    at require (node.js:411:14)
    at Object.<anonymous> (/home/node/app/app.js:1:73)
    at Module._compile (node.js:462:23)
    at Module._loadScriptSync (node.js:469:10)
    at Module.loadSync (node.js:338:12)
    at Object.runMain (node.js:522:24)
    at Array.<anonymous> (node.js:756:12)
    at EventEmitter._tickCallback (node.js:55:22)
    at node.js:773:9 

質問、私が従っている間違ったステップは何ですか?

Express をインストールした後の出力は次のとおりです。

C:\MYSite>npm install express
npm http GET https://registry.npmjs.org/express
npm http 200 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/connect/2.7.2
npm http GET https://registry.npmjs.org/commander/0.6.1
npm http GET https://registry.npmjs.org/fresh/0.1.0
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/cookie/0.0.5
npm http GET https://registry.npmjs.org/buffer-crc32/0.1.1
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/cookie-signature/0.0.1
npm http GET https://registry.npmjs.org/mkdirp/0.3.3
npm http GET https://registry.npmjs.org/send/0.1.0
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/methods/0.0.1
npm WARN package.json methods@0.0.1 No README.md file found!
npm http 304 https://registry.npmjs.org/fresh/0.1.0
npm http 200 https://registry.npmjs.org/commander/0.6.1
npm http GET https://registry.npmjs.org/commander/-/commander-0.6.1.tgz
npm http 304 https://registry.npmjs.org/cookie/0.0.5
npm http 200 https://registry.npmjs.org/connect/2.7.2
npm http 304 https://registry.npmjs.org/buffer-crc32/0.1.1
npm http GET https://registry.npmjs.org/connect/-/connect-2.7.2.tgz
npm http 304 https://registry.npmjs.org/debug
npm http 200 https://registry.npmjs.org/cookie-signature/0.0.1
npm http GET https://registry.npmjs.org/cookie-signature/-/cookie-signature-0.0.1.tgz
npm http 200 https://registry.npmjs.org/mkdirp/0.3.3
npm http GET https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.3.tgz
npm http 304 https://registry.npmjs.org/send/0.1.0
npm http 200 https://registry.npmjs.org/commander/-/commander-0.6.1.tgz
npm http 200 https://registry.npmjs.org/connect/-/connect-2.7.2.tgz
npm http 200 https://registry.npmjs.org/cookie-signature/-/cookie-signature-0.0.1.tgz
npm http 200 https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.3.tgz
npm http GET https://registry.npmjs.org/mime/1.2.6
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http GET https://registry.npmjs.org/formidable/1.0.11
npm http GET https://registry.npmjs.org/bytes/0.1.0
npm http GET https://registry.npmjs.org/qs/0.5.1
npm http 304 https://registry.npmjs.org/mime/1.2.6
npm http 304 https://registry.npmjs.org/bytes/0.1.0
npm http 304 https://registry.npmjs.org/pause/0.0.1
npm http 200 https://registry.npmjs.org/qs/0.5.1
npm http GET https://registry.npmjs.org/qs/-/qs-0.5.1.tgz
npm http 200 https://registry.npmjs.org/formidable/1.0.11
npm http GET https://registry.npmjs.org/formidable/-/formidable-1.0.11.tgz
npm http 200 https://registry.npmjs.org/qs/-/qs-0.5.1.tgz
npm http 200 https://registry.npmjs.org/formidable/-/formidable-1.0.11.tgz
express@3.1.0 node_modules\express
├── methods@0.0.1
├── fresh@0.1.0
├── buffer-crc32@0.1.1
├── cookie-signature@0.0.1
├── cookie@0.0.5
├── range-parser@0.0.4
├── commander@0.6.1
├── debug@0.7.2
├── mkdirp@0.3.3
├── send@0.1.0 (mime@1.2.6)
└── connect@2.7.2 (pause@0.0.1, bytes@0.1.0, formidable@1.0.11, qs@0.5.1)
4

2 に答える 2

4

Express をグローバルではなくローカルにインストールした

C:\MYSite>npm install Express

MYSiteしたがって、このフォルダーからのみ実行する必要があります。しかし、別の場所から実行しています。

C:> ノード app.js

したがって、エラーが発生し続けますError: Cannot find module 'express'

于 2013-03-18T11:37:27.440 に答える