Skip to content

Question: Net.createConnection is not a function #1681

@ghost

Description

Is 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions