2016-06-17 10 views
1

大学のサーバにubuntuインスタンスを作成しました。 NodeJSとNPMをインストールし、FTP接続でファイルを送信できます。NodeJS - SyntaxError:予期しないトークンILLEGAL

次のNodeJS Webサーバーファイルを私のintanceに送信し、インスタンスip-adressで実行したいとします。

var http = require(“http“); 
http.createServer(function(request, response) { 
    response.writeHead(200, {‚content-type’: ‚text/plain‚}); 
    response.write(‘Hello World’); 
    response.end; 
}).listen(3000‚141.28.107.7); 
console.log(“server is running“); 

私は

sudo nodejs server.js 

私は、次のエラーメッセージが出ていてこのファイルを実行すると:

sudo: unable to resolve host nodejs 
/home/robin/files/webserver.js:1 
(function (exports, require, module, __filename, __dirname) { var http = require(“http“); 
                       ^

SyntaxError: Unexpected token ILLEGAL 
    at exports.runInThisContext (vm.js:53:16) 
    at Module._compile (module.js:387:25) 
    at Object.Module._extensions..js (module.js:422:10) 
    at Module.load (module.js:357:32) 
    at Function.Module._load (module.js:314:12) 
    at Function.Module.runMain (module.js:447:10) 
    at startup (node.js:148:18) 
    at node.js:405:3 

私のエラーは推論にありますか? ありがとう!

+0

引用符で囲まれた野生の推測ホスト名 '.listen(3000、" 141.28.107.7 ");' –

答えて

6

あなたは奇妙な引用符を使用しているようです:。標準的な二重引用符"または一重引用符'を使用してください。

var http = require('http'); 
http.createServer(function(request, response) { 
    response.writeHead(200, {'Content-Type': 'text/plain'}); 
    response.write('Hello World'); 
    response.end(); 
}).listen(3000‚'141.28.107.7'); 
console.log('server is running'); 
関連する問題