无法在opsworks AWS中使用Node.js和MySql连接

时间:2015-02-12 06:05:25

标签: javascript mysql node.js amazon-web-services amazon-s3

我试图在aws

中的opsworks中连接两个图层
  1. 节点js app服务器。
  2. Mysql图层
  3. 我创建了一个node.js应用程序并部署在AWS mysql连接详细信息代码中的s3存储库中,格式如下

    exports.db = {"adapter":"mysql",
    
              "database":"DBname",
    
              "password":"xyz",
    
              "port":3306,
    
              "reconnect":true,
    
              "username":"root",
    
              "data_source_provider":"rds",
    
              "host":"localhost"
    
             }
    
    exports.memcached = {"port":11211,
    
                     "host":null}
    

    连接的实际代码是......

    var express = require('express');
    
    var app = express();
    
    var mysql=require('./shared/config/opsworks.js');
    
    app.get('/', function(req, res) 
    {
    
     var connection = mysql.exports.db;
    
        connection.connect();
    
        connection.query('CREATE TABLE SAMPLE(PK_ID INT NOT NULL AUTO_INCREMENT,USERNAME VARCHAR(100) NOT NULL, PRIMARY KEY ( PK_ID )); ',
    
        function(err, rows, fields) {
    
        connection.end();
    
        res.writeHead(200,{'Content-Type':'text/plain'});
    
              if (!err)
    
               {
    
              res.write('TABLE CREATED SUCCESSFULLY');
    
              console.log('TABLE CREATED SUCCESSFULLY');
    
              }
             else
             {
                  res.write('ERROR');
                  console.log(err);
             }
    
           });
    
            res.write('OUTSIDE QUERY');
    
        res.end();
    
    });
    
    app.use(express.static('public'));
    
    app.listen(80);
    
    console.log('Listening on port 80');
    

    当我点击公共IP时,代码无效,任何人都可以帮我纠正代码

0 个答案:

没有答案