0

I would like to connect to MySQL database through Node.js in my Angular Universal project.

Connection code is simple:

var mysql = require('mysql');

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

connection.connect(function(err) {
          if (err) {
            console.log("Error connecting to DB: " + err);
            throw err;
          }
        });

First I am getting the following error:

TypeError: Cannot read property 'on' of undefined
        at Protocol._enqueue (/Applications/MAMP/htdocs/Angular2/myproject/node_modules/mysql/lib/protocol/Protocol.js:152:5)
...

Then after several seconds there is the following error:

Error connecting to DB: Error: Connection lost: The server closed the connection.

Advice me please what should be done in this case to fix the issue.

Thanks a lot.

1 Answer 1

1

If I change the version for zone.js in package.json to 0.7.4, everything works without problems.

Sign up to request clarification or add additional context in comments.

1 Comment

The issue was solved when I install the latest version of Zone.js: npm install zone.js@latest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.