使用节点 javascript 的意外令牌非法
Unexpected token ILLEGAL using node javascript
我正在尝试使用节点 JavaScript 执行命令,但我在第 1 行的 javascript.Its 中得到 "Uncaught SyntaxError: Unexpected token ILLEGAL"。
var express = require('express');
var mongodb = require('mongodb');
var app = express();
var MongoClient = require('mongodb').MongoClient;
var db;
var port = process.env.PORT || 8080;
MongoClient.connect(mongo_host, function(err, database) {
if(err) throw err;
db = database;
app.listen(port, function () {
console.log('listening port' + port);
});
});
app.get('/', function (req, res) {
res.json({ message: 'Bienvenue Azure!' });
});
app.get('/plante', function (req, res) {
db.collection("plante").find().toArray(function(err, users) {
res.send(users);
});
});
注意:mongo_host 是 Git 存储库 url 以连接 azure
然后显示如下错误:
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:404:25)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:138:18)
at node.js:974:3
您的分号不是标准分号。他们是 \u037e
(Greek Question Mark)。尝试将它们切换回标准分号,然后 运行 代码。
有人一直在阅读twitter。
正如@dvlsg所说,这是一个语法错误,由一些非法符号引起,如;
。
有一个类似的 SO 线程对您有帮助,请参阅 No visible cause for "Unexpected token ILLEGAL"。
我通过将 Azure Web 应用服务中的节点版本更新到最新版本(在我的例子中是 10.6.0)解决了这个错误。它一直对包含 ES6 的行犹豫不决。改变它的一种方法是使用环境变量。您可以在应用门户的 'Application settings' 中更改它。更改 WEBSITE_NODE_DEFAULT_VERSION
我正在尝试使用节点 JavaScript 执行命令,但我在第 1 行的 javascript.Its 中得到 "Uncaught SyntaxError: Unexpected token ILLEGAL"。
var express = require('express');
var mongodb = require('mongodb');
var app = express();
var MongoClient = require('mongodb').MongoClient;
var db;
var port = process.env.PORT || 8080;
MongoClient.connect(mongo_host, function(err, database) {
if(err) throw err;
db = database;
app.listen(port, function () {
console.log('listening port' + port);
});
});
app.get('/', function (req, res) {
res.json({ message: 'Bienvenue Azure!' });
});
app.get('/plante', function (req, res) {
db.collection("plante").find().toArray(function(err, users) {
res.send(users);
});
});
注意:mongo_host 是 Git 存储库 url 以连接 azure
然后显示如下错误:
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:404:25)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:138:18)
at node.js:974:3
您的分号不是标准分号。他们是 \u037e
(Greek Question Mark)。尝试将它们切换回标准分号,然后 运行 代码。
有人一直在阅读twitter。
正如@dvlsg所说,这是一个语法错误,由一些非法符号引起,如;
。
有一个类似的 SO 线程对您有帮助,请参阅 No visible cause for "Unexpected token ILLEGAL"。
我通过将 Azure Web 应用服务中的节点版本更新到最新版本(在我的例子中是 10.6.0)解决了这个错误。它一直对包含 ES6 的行犹豫不决。改变它的一种方法是使用环境变量。您可以在应用门户的 'Application settings' 中更改它。更改 WEBSITE_NODE_DEFAULT_VERSION