Saturday, 2 June 2018

Angular electron mysql create conncetion is not a function

I haveinstalled node js mysql and mysql types via

"@types/mysql": "^2.15.4",
"mysql": "^2.15.0"

Am using electron with angular2 so in my component i wanted to create a conncection via

import * as mysql from 'mysql'

 @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
 })

 export class AppComponent implements OnInit {
    connection: any;
    constructor() {
       this.connection = mysql.createConnection({
           host: 'localhost',
           user: 'root',
           password: '5378@Geowan5378',
           database: 'company'
        });

    this.connection.connect((err) => {
        if (err) {
            console.log('error connecting', err);
        }else{
            console.log("connection was a success ");
        }
    });

}   // DI

But now am getting an error

TypeError: o.createConnection is not a function

This is the only component so far as am only learning on electron and mysql. Where am i going wrong?

Note that the error happens when i call

this.connection.connect

I undestand that this may be caused by Net library which is not available in the browser but in my case am running electron . to launch my app so am not using the browser

Or how can i then connect the app directly with mysql without using a server side framework



from Angular electron mysql create conncetion is not a function

No comments:

Post a Comment