2017-02-25 4 views
0

ノードserver.jsファイルを使用する必要があるプロジェクトで作業しています。プロジェクトのドキュメントでは、ターミナルで 'node server.js'を入力してサーバーを起動すると書かれていますが、そのときにエラーが発生しましたが、 'express'モジュールを見つけることができません。ノードserver.jsが応答しないエラーメッセージ

Error: Cannot find module 'express' 
    at Function.Module._resolveFilename (module.js:455:15) 
    at Function.Module._load (module.js:403:25) 
    at Module.require (module.js:483:17) 
    at require (internal/module.js:20:19) 
    at Object.<anonymous> (/Users/.../Desktop/react/react-app-project/server.js:6:15) 
    at Module._compile (module.js:556:32) 
    at Object.Module._extensions..js (module.js:565:10) 
    at Module.load (module.js:473:32) 
    at tryModuleLoad (module.js:432:12) 
    at Function.Module._load (module.js:424:3) 

これはserver.js

var express = require('express'); 
var app = express(); 

/* 
this says: serve all the files in the src directory if they match the URL 

For example, if the client requests http://server/css/app.css then the file in src/css/app.css will be served 
But if the client requests http://server/step-2 then since there is no file by that name the middleware will call next() 
*/ 
app.use(express.static(__dirname + '/src')); 

/* insert any app.get or app.post you need here. only if you do the advanced part */ 

/* 
This says: for any path NOT served by the middleware above, send the file called index.html instead. 
For example, if the client requests http://server/step-2 the server will send the file index.html. Then on the browser, React Router will load the appropriate component 
*/ 
app.get('/*', function(request, response) { 
    response.sendFile(__dirname + '/src/index.html'); 
}); 
app.listen(process.env.PORT || 8080, function() { 
    console.log('server started'); 
}); 

答えて

0

のコードはモジュールを見つけることができませんである理由は、あなたがまだExpressをインストールしていないということです

'を表現します'。

溶液:npm install express

関連する問題