I have successfully set up Node.js, MySQL, and MySQL types.
"@types/mysql": "^2.15.4",
"mysql": "^2.15.0"
Currently, I am working with Electron and Angular 2. In my component, I attempted to establish a connection using the following code:
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 ");
}
});
} // Dependency Injection
However, I encountered the following error:
TypeError: o.createConnection is not a function
This issue arises when I call
this.connection.connect
It seems like the Net library might not be available in the browser. Nonetheless, I am running electron .
to launch my app, so the browser shouldn't be causing this problem.
Is there a way to connect the app directly to MySQL without relying on a server-side framework?