how to connect nodejs application to google cloud mysql (no bs) - javascript

I've seen a ton of conflicting answers and I want this thread to be very conclusive. I'm running a Node.js app that needs to have a server endpoint to call a google mysql database.
The SQL call I'm making in server.js should be fine, empty though. Regardless, the break point isn't at the SQL call.
There's no enforced password set up so I have those credentials set up as
...
user: 'root',
password: '',
...
and I'm currently not using the socketPort configuration option.
Respond if you need any more information about the database.
This is a full stack trace, you can see it yourself by running npm run dev
Error connecting: Error: connect ETIMEDOUTat Connection._handleConnectTimeout (C:\Users\********\Projects\security-project\security-dashboard\node_modules\mysql\lib\Connection.js:412:13)
at Object.onceWrapper (events.js:286:20)
at Socket.emit (events.js:198:13)
at Socket._onTimeout (net.js:442:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
--------------------
at Protocol._enqueue (C:\Users\********\Projects\security-project\security-dashboard\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\********\Projects\security-project\security-dashboard\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Users\*******\Projects\security-project\security-dashboard\node_modules\mysql\lib\Connection.js:119:18)
at Object.<anonymous> (C:\Users\*********\Projects\security-project\security-dashboard\database.js:26:12)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
[ ready ] compiled successfully

Related

MySQL Timed out when starting server

So i was working on a login system with MySql. At first it worked perfectly, but after a bit of time it stopped working and now when I start it it gives me
Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (I:\Websites\backend\node_modules\mysql\lib\Connection.js:409:13)
at Object.onceWrapper (events.js:519:28)
at Socket.emit (events.js:400:28)
at Socket._onTimeout (net.js:484:8)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
--------------------
at Protocol._enqueue (I:\Websites\backend\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (I:\Websites\backend\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (I:\Websites\backend\node_modules\mysql\lib\Connection.js:116:18)
at Object.<anonymous> (I:\Websites\backend\Main.js:20:4)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
What is also important to say is that I do not host the Database on my PC, I have rented a server for it. Hope that someone can help

Error: Cannot find module "moduleIntro.js" when running "http"

I tried a basic beginner program in Node.Js where I wanted to use the built-in module 'http'. After executing a basic program of http.createServer(). Below is my source code.
var http = require('http');
http.createServer(function (req, res) {
res.write('Hello World!');
res.end();
}).listen(8080);
When running the code in cmd it didn't run and displayed the following error.
events.js:287
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::8080
at Server.setupListenHandle [as _listen2] (net.js:1313:16)
at listenInCluster (net.js:1361:12)
at Server.listen (net.js:1449:7)
at Object.<anonymous> (F:\NodeJS\first app\w3schools\moduleIntro,.js:7:4)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1340:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 8080
}
Ok, it's not problem in your code actually 8080 already running anywhere else so you can't run the same port number at a time so just close all running process Or you just shut down your PC and run again the problem will be resolve.

how to run mysql on express js in linux mint

I used to run mysql using xampp, do I have to run mysql service?
I followed this tutorial -> http://mfikri.com/en/blog/nodejs-mysql-crud
I'm confused in step #2
Server is running at port 8000
/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/index.js:23
if(err) throw err;
^
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1136:16)
--------------------
at Protocol._enqueue (/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/node_modules/mysql/lib/Connection.js:118:18)
at Object.<anonymous> (/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/index.js:22:6)
at Module._compile (internal/modules/cjs/loader.js:1128:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Module.load (internal/modules/cjs/loader.js:983:32)
at Function.Module._load (internal/modules/cjs/loader.js:891:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
It seems like the connection to your db was refused. Make sure you are using the correct database account and that it has privileges.
Also make sure to whitelist your app from db.
You need to whitelist the following ips: 127.0.0.1 and localhost
this thread can possibly be of help: node.js mysql error: ECONNREFUSED
Yes, you need a MySQL DB running. The easiest way is to install Docker on your machine, and use the official MySQL container.

Why am I getting error "requires a generator function"

I installed the module "koa-cache-control" via npm.
I added the following lines to my index.js.
const cacheControl = require('koa-cache-control');
Then...
app.use(cacheControl({
noCache: true
}));
Here is the error I get when starting node.
Any clues?
AssertionError: app.use() requires a generator function
at Application.app.use
(/home/www/node_modules/koa/lib/application.js:106:5)
at Object.<anonymous> (/home/www/index.js:17:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
Thanks!
You seem to be using an old version of Koa. The 1.x versions used a generator-based type of middleware, which was changed to Promises in version 2.
You'll either have to update Koa or use the old version 1.0.0 of koa-cache-control.

ECONNREFUSED connect when running Selenium-webdriver [duplicate]

This question already has answers here:
Unable to run Protractor - ECONNREFUSED connect ECONNREFUSED
(12 answers)
Closed 6 years ago.
I am trying see the actual html content before being rendered by the browser. So I am using selenium-webdriver in node.js.
Here's my code and the error I'm getting:
Code
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
usingServer('http://localhost:4444/wd/hub').
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://www.example.com/example/abc');
driver.getPageSource().then(function(html) {
console.log(html);
return true;
});
driver.quit();
Error
/home/abhishek/node_modules/selenium-webdriver/lib/webdriver/promise.js:1761
throw error;
^
Error: ECONNREFUSED connect ECONNREFUSED
at ClientRequest.<anonymous> (/home/abhishek/node_modules/selenium-webdriver/http/index.js:145:16)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/home/abhishek/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:149:22)
at Function.webdriver.WebDriver.createSession (/home/abhishek/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:123:30)
at Builder.build (/home/abhishek/node_modules/selenium-webdriver/builder.js:294:22)
at Object.<anonymous> (/home/abhishek/crawler_postman/crawler_selenium.js:15:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
That means webserver is not running. Try running webdriver-manager start --standalone in a new command line window or tab
From: https://stackoverflow.com/a/21124867/577977

Categories

Resources