Question: Net.createConnection is not a function
See original GitHub issueIs more a question than an error, I already know in a browser environment the net module is supposed to not exists, but I’m writing a electron app with angular2 and i’ve tested this script:
<script>
var connection = mysql.createConnection({
host : 'localhost',
user : 'user',
password : 'password',
database : 'test'
});
console.log( connection.connect() )
</script>
and is working good, since electron is node based and can interact with filesystem and net.
But the problem come when I try to put in a angular2 component this:
import { Component } from '@angular/core';
import * as mysql from 'mysql';
export class AppComponent {
constructor() {
var connection = mysql.createConnection({
host : 'localhost',
user : 'user',
password : 'password',
database : 'test'
});
console.log( connection.connect() )
}
}
it says: Net.createConnection is not a function…so my question is… why? what’s happening?
Any hint is appreciated. Many thanks in advance.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (5 by maintainers)
Top Results From Across the Web
Error in MySQL library for Node.js - Stack Overflow
The error you're getting about Net.createConnection not being a function means it's coming up as an empty object and the error is related...
Read more >Net - node - Read the Docs
This function is asynchronous. When the 'connect' event is emitted the socket is established. If there is a problem connecting, the 'connect' event...
Read more >Net | Node.js v18 API - NodeJS Dev
The node:net module provides an asynchronous network API for creating stream-based TCP or IPC servers ( net.createServer() ) and clients ( net.createConnection ......
Read more >Uncaught TypeError: net.createConnection is not a function
I am connecting my server (which uses C++) to client (which uses React Js) through APACHE THRIFT. However, I got the error "Uncaught ......
Read more >Node.js - Net Module - Tutorialspoint
Sr.No. Method & Description. 1. net.createServer([options][, connectionListener]) ... net.createConnection(options[, connectionListener]). A factory method ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @codekraft-studio.
If your component are rendered on client-side the mysql node module not work, i’m tried to use with vue.js, the module Net does’t work on the client side, you ned to process the mysql query on the server-side.
The alternative are
This isn’t an “Angularjs” thing, its a nodejs problem. I’ve facing the same thing using React.
There should be some kind of fix or idea of why this would happen when connecting client side…