Express を使用して JSON 応答を生成しています
var express = require('express')
, async = require('async')
, http = require('http')
, mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: 'xxx',
password: "xxx",
database: 'db'
});
connection.connect();
// all environments
app.set('port', process.env.PORT || 1234);
//
//REQUEST FOR FIRST REQUEST
//
app.get('/',function(request,response){
var restaurants, collegeTimings;
async.series( [
// Get the first table contents
function ( callback ) {
connection.query('SELECT * FROM restaurants', function(err, rows, fields)
{
console.log('Connection result error '+err);
val1 = rows;
callback();
});
},
// Get the second table contents
function ( callback ) {
connection.query('SELECT * FROM collegeTimings', function(err, rows, fields)
{
console.log('Connection result error '+err);
collegeTimings = rows;
callback();
});
}
// Send the response
], function ( error, results ) {
response.json({
'val1' : restaurants,
'collegeimings' : collegeTimings
});
} );
//
//REQUEST FOR SECOND REQUEST
//
app.get('/class',function(request,response){
var clas, collegeTimings;
async.series( [
// Get the first table contents
function ( callback ) {
connection.query('SELECT * FROM college', function(err, rows, fields)
{
console.log('Connection result error '+err);
college = rows;
callback();
});
},
// Get the second table contents
function ( callback ) {
connection.query('SELECT * FROM RcollegeTimings', function(err, rows, fields)
{
console.log('Connection result error '+err);
collegeTimings = rows;
callback();
});
}
// Send the response
], function ( error, results ) {
response.json({
'college' : class,
'collegeTimings' : collegeTimings
});
} );
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
次のようなエラーが発生しています::
SyntaxError: Unexpected end of input
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
これを解決する方法