简体   繁体   English

NodeJS-SyntaxError:意外令牌非法

[英]NodeJS - SyntaxError: Unexpected token ILLEGAL

I've created an ubuntu instance on my university server. 我在大学服务器上创建了一个ubuntu实例。 I've installed NodeJS and NPM and can send files with a FTP connection. 我已经安装了NodeJS和NPM,并且可以通过FTP连接发送文件。

I sent following NodeJS webserver file to my intance and want to run it on the instance ip-adress. 我向我的实例发送了以下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“);

When I run this file with 当我用

sudo nodejs server.js

I'm getting the following error message: 我收到以下错误消息:

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

Where's my error in reasoning? 我的推理错误在哪里? Thanks! 谢谢!

You seem to be using weird quotes : . 您似乎在使用奇怪的引号: Use standard double quotes " or single quotes ' . 使用标准的双引号"或单引号'

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM