gpt4 book ai didi

node.js - NodeJS - 语法错误 : Unexpected token ILLEGAL

转载 作者:太空宇宙 更新时间:2023-11-03 22:44:00 25 4
gpt4 key购买 nike

我已经在我的大学服务器上创建了一个 ubuntu 实例。我已经安装了 NodeJS 和 NPM,并且可以通过 FTP 连接发送文件。

我将以下 NodeJS Web 服务器文件发送到我的实例,并希望在实例 IP 地址上运行它。

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');

关于node.js - NodeJS - 语法错误 : Unexpected token ILLEGAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37890876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com