2016-05-22 15 views
0

nodejsプロジェクトにbowerを使用し、jquery + bootstrapをインストールしようとしています。しかし、私は常に主題の誤りを得る。私は何が間違っているのか分かりません。Uncaught SyntaxError:予期せぬトークン<jquery.min.js:1

コードはここにある:

jsfiddle.net/valsaven/8d6e03um/ 

フォルダ構造:

チャット

  • bower_components
  • node_modules
  • app.js
  • index.htmlを

答えて

0

問題は、リクエストにサービスを提供している、あなたのバックエンドのコードではなく、フロントエンドです。

var app = http.createServer(function(req, res) { 
    res.writeHead(200, { 
     'Content-type': 'text/html' 
    }); 
    res.end(index); 
}); 

このコードはjscssファイルを含むすべての要求のために実行されます。したがって、jsリクエストにindex.htmlという内容が表示されます。したがって、JavaScriptエンジンでは、html<タグを含むファイルの解析中にエラーが表示されます。

解決策は、特定のルートを定義することです。

var http = require('http'), 
fs = require('fs'), 
path = require('path'), 
express= require('express'), 
index = fs.readFileSync(__dirname + '/index.html'); 

var app = express(); 
var server = require('http').Server(app); 
var io = require('socket.io')(server); 

app.use('/bower_components', express.static('bower_components')); 

app.get('/', function(req, res){ 
    res.writeHead(200, { 
     'Content-type': 'text/html' 
    }); 
    res.end(index); 
}); 

server.listen(3000, function() { 
    console.log('Server listening on port 3000'); 
}); 
関連する問題