0

I'm Working on Database connection part with Npm and installed package mysql. When I try to connect with Mysql script, I'm getting below error :

Cannot resolve module 'net'
Cannot resolve module 'tls'
Cannot resolve module 'fs'

Mysql Connection Code :

var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'xxxx',
    password: 'xxxx',
    database: 'xxxx',
    port: 'xxxx'
});

connection.connect();

I've googled and implemented all the possible methods suggested in forums. But the error is not resolving. Please do let me know how can I come out of it..

BBD
  • 31
  • 1
  • 5
  • Is this the complete code you have in your application? – Shaharyar Apr 12 '17 at 09:52
  • Yes, I had just started. Wanted to check if above code is correct.. I found that issue. – BBD Apr 12 '17 at 10:06
  • it's a silly question but whatever, you execute the code in browser ? the default modules are unable to be loaded ..maybe there is an problem with your NodeJS installation and fails to resolve paths. – Gntem Apr 12 '17 at 10:17

1 Answers1

0

I think that your mysql package doesnt found 'net', 'tls' and 'fs' packages, could you try reinstalling them globally using npm?

Use:

npm install -g net tls fs
  • Is it even possible? They're default packages included in `nodejs`. – Shaharyar Apr 12 '17 at 10:07
  • I have tried that, now I'm getting error as : events.js:141 // unhandled error. Error: listen EADDRINUSE 0.0.0.0:8080 – BBD Apr 12 '17 at 10:08
  • Hi, @BhushanD check this: http://stackoverflow.com/questions/9898372/how-to-fix-error-listen-eaddrinuse-while-using-nodejs – Jesús Márquez Apr 12 '17 at 10:17
  • default port for MySQL is set to 3306 there is no way that the code snippet attempts to connect to 8080 – Gntem Apr 12 '17 at 10:19