Home Trying to connect to the ClearDB, and getting can't use require errors
Reply: 0

Trying to connect to the ClearDB, and getting can't use require errors

jsauder81
1#
jsauder81 Published in 2017-11-14 21:32:29Z

We're trying to connect to our ClearDB database. When we use "node in the terminal, the database will update; however, when we try and do it in our Angular app, it does not work. We are using express for routing, and the mysql node module.

var express = require("express");
var app = angular.module("myApp");

var application = express();
app.use(express.logger());

require('mysql');

app.controller('sqlCtrl', function($scope) {
    $scope.submit = function(username, password) {
        // use username and password to query the database
        $scope.username = null;
        $scope.password = null;
        return username + " " + password;
    }

    var con = mysql.createConnection({
         host: "hostname",
         user: "username",
         password: "pass",
         database: "database name"
     });

     con.connect();


    application.get('/', function(request, response) {
        console.log("Connected!");

        con.query("Select * FROM user", function (err, result) {
            if (err) throw err;
            console.log(result);
            con.end();
        });

    });
     con.end();
});

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.344681 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO