0

我正在使用 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

如何解决这个问题

4

1 回答 1

0

app.get('/'...错过了另一个});

于 2013-08-23T04:23:19.840 回答