readFileSync() を使用して、html ファイルの内容をノード js ファイルに表示しようとしています。しかし、私はこのエラーが発生します:
Error: ENOENT, no such file or directory 'index.html'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.readFileSync (fs.js:284:15)
at port (/app/web.js:6:22)
at callbacks (/app/node_modules/express/lib/router/index.js:161:37)
at param (/app/node_modules/express/lib/router/index.js:135:11)
at pass (/app/node_modules/express/lib/router/index.js:142:5)
at Router._dispatch (/app/node_modules/express/lib/router/index.js:170:5)
at Object.router (/app/node_modules/express/lib/router/index.js:33:10)
at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.expressInit [as handle] (/app/node_modules/express/lib/middleware.js:30:5)
ここに私のweb.jsファイルがあります:
var express = require('express');
var app = express.createServer(express.logger());
var fs=require('fs');
app.get('/', function(request, response) {
// response.send('Hello World2 !');
response.send(fs.readFileSync('index.html').toString());
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
「web.js」ファイルと「index.html」は、私の github リポジトリの次のアドレスにあります。
https://github.com/myUsername/bitstarter/blob/master/node-js-sample/web.js
https://github.com/myUsername/bitstarter/blob/master/node-js-sample/index.html
「index.html」に対処するためにさまざまなパスを試しましたが、次のように機能しませんでした
/bitstarter/blob/master/node-js-sample/index.html
/node-js-sample/index.html
/bitstarter/node-js-sample/index.html
./index.html
! AWS EC2 ubuntun 12-4 を使用しています。私は何時間もこのエラーに悩まされてきました! どんな助けでも大歓迎です。