[英]NodeJS - SyntaxError: Unexpected token ILLEGAL
我在大學服務器上創建了一個ubuntu實例。 我已經安裝了NodeJS和NPM,並且可以通過FTP連接發送文件。
我向我的實例發送了以下NodeJS Web服務器文件,並希望在實例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
我的推理錯誤在哪里? 謝謝!
您似乎在使用奇怪的引號: “
。 使用標准的雙引號"
或單引號'
。
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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.