[英]SyntaxError: Unexpected token ILLEGAL nodes
I'm trying to start a localhost server via nodejs and mySql database. 我正在尝试通过nodejs和mySql数据库启动本地主机服务器。 I'm getting an error which says:
我收到一条错误消息:
SyntaxError: Unexpected token ILLEGAL at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:413:25) at Object.Module._extensions..js (module.js:452:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at /Users/Liran/Desktop/nodejs/server.js:34:13 at Array.forEach (native) at Object. (/Users/Liran/Desktop/nodejs/server.js:32:7)
this error is caused by running the following javascript code: 此错误是由运行以下javascript代码引起的:
var express = require('express');
var app = express();
var mysql = require('mysql')
var fs = require('fs'),
path = require('path');
var ipaddress = '127.0.0.1';
var port = 8080;
// ----------- MySQL Connection ------
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '1',
});
connection.connect();
// --------- Set upload directory -------
app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyParser({ keepExtensions: true, uploadDir: '../public/images/' }));
});
app.fs = fs;
// ------------ ROUTES ---------------
var RouteDir = 'routes',
files = fs.readdirSync(RouteDir);
files.forEach(function (file) {
var filePath = path.resolve('./', RouteDir, file),
route = require(filePath);
route.init(app, connection);
});
// ----------- Run Server ----------------
app.listen(port, ipaddress, function()
{
console.log('%s: Node server started on %s:%d ...',
Date(Date.now() ), ipaddress, port);
});`enter code here`
basically all I'm doing is to set the server ip & port and connect it to the mysql db.. please tell me what am I doing wrong and why is that error appears? 基本上我要做的就是设置服务器ip和端口并将其连接到mysql db ..请告诉我我在做什么错,为什么会出现该错误? and if there are any code changes that I should make in order to make a good localhost server via nodejs and mysql please let me know :) Thanks in advance!
如果要通过nodejs和mysql创建一个好的本地主机服务器,如果我应该进行任何代码更改,请告诉我:)预先感谢!
One of the files you are require()
ing in your files.forEach()
callback has an illegal token. 您文件中的
require()
文件之一files.forEach()
回调具有非法令牌。 You may want to insert a debug statement before the require()
so you can determine which file is having the problem. 您可能需要在
require()
之前插入调试语句,以便确定哪个文件有问题。 From there, you can use a linter like jshint
to find the exact location of the illegal token in that file. 从那里,您可以使用像
jshint
这样的jshint
来查找该文件中非法令牌的确切位置。
In your code 在你的代码中
// ----------- MySQL Connection ------ var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '1', }); connection.connect();
you have an extra coma next to the password. 您在密码旁边还有一个逗号。
Thats the only actual error I see 那是我看到的唯一实际错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.