Here is my database connection code
'use strict';
const config = require('../config');
const Mongoose = require('mongoose').connect(config.dbURI);
const mongoose = require('mongoose');
var options = {
promiseLibrary: require('bluebird'), useNewUrlParser: true, useUnifiedTopology: true
};
var mongodbUri = 'mongodb+srv://chatcat:chatcat#mychatcatdb-xlous.mongodb.net/test?retryWrites=true&w=majority'
mongoose.connect(mongodbUri, options);
var conn = mongoose.connection;
conn.on('error', console.error.bind(console, 'connection error:'));
module.exports = {
Mongoose
}
I'm getting this type of warning. i have also installed all of the packages which is required.
warning is just be like (node:17592) DeprecationWarning, (node:17592) UnhandledPromiseRejectionWarning.
what is the reason behind the this type of Warning ?
i just started learning node js.
please anyone help me to solve this warning?
D:\Node\ChatCAT\ChatCAT_Begin>node server
(node:17592) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
chatCat Running on Port: 3000
(node:17592) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
connection error: MongoNetworkError: failed to connect to server [mychatcatdb-shard-00-02-xlous.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to mychatcatdb-shard-00-02-xlous.mongodb.net:27017 closed
at TLSSocket.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnection.js:372:9)
at Object.onceWrapper (events.js:418:26)
at TLSSocket.emit (events.js:311:20)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}]
at Pool.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwerver.js:438:11)
at Pool.emit (events.js:311:20)
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwool.js:561:14
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwool.js:1008:9
at callback (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:97:5)
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:124:7
at _callback (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:349:5)
at Connection.errorHandler (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:365:5) at Object.onceWrapper (events.js:418:26)
at Connection.emit (events.js:311:20)
at TLSSocket.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnection.js:370:12)
at Object.onceWrapper (events.js:418:26)
at TLSSocket.emit (events.js:311:20)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}
(node:17592) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mychatcatdb-shard-00-02-xlous.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to mychatcatdb-shard-00-02-xlous.mongodb.net:27017 closed
at TLSSocket.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnection.js:372:9)
at Object.onceWrapper (events.js:418:26)
at TLSSocket.emit (events.js:311:20)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}]
at Pool.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwerver.js:438:11)
at Pool.emit (events.js:311:20)
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwool.js:561:14
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwool.js:1008:9
at callback (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:97:5)
at D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:124:7
at _callback (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:349:5)
at Connection.errorHandler (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnect.js:365:5) at Object.onceWrapper (events.js:418:26)
at Connection.emit (events.js:311:20)
at TLSSocket.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwonnection.js:370:12)
at Object.onceWrapper (events.js:418:26)
at TLSSocket.emit (events.js:311:20)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7)
(node:17592) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:17592) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
connection error: MongooseError [MongooseServerSelectionError]: connection <monitor> to 3.7.80.251:27017 closed
at new MongooseServerSelectionError (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwction.js:22:11)
at NativeConnection.Connection.openUri (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGioose\lib\connection.js:823:32)
at Mongoose.connect (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGioose\lib\index.js:333:15)
at Object.<anonymous> (D:\Node\ChatCAT\ChatCAT_Begin\app\db\index.js:33:10)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGi.js:5:12)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Node\ChatCAT\ChatCAT_Begin\app\index.js:11:11)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14) {
message: 'connection <monitor> to 3.7.80.251:27017 closed',
name: 'MongooseServerSelectionError',
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map {
'mychatcatdb-shard-00-00-xlous.mongodb.net:27017' => [ServerDescription],
'mychatcatdb-shard-00-01-xlous.mongodb.net:27017' => [ServerDescription],
'mychatcatdb-shard-00-02-xlous.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
},
[Symbol(mongoErrorContextSymbol)]: {}
}
(node:17592) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connection <monitor> to 3.7.80.251:27017 closed
at new MongooseServerSelectionError (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGiDtbLrcW77HPEwrJM2Ej2yFNYwction.js:22:11)
at NativeConnection.Connection.openUri (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGioose\lib\connection.js:823:32)
at Mongoose.connect (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGioose\lib\index.js:333:15)
at Object.<anonymous> (D:\Node\ChatCAT\ChatCAT_Begin\app\db\index.js:33:10)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Node\ChatCGV9Jm2u7rmsCe65wKzPTw5jtS38n2tVEGi.js:5:12)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Node\ChatCAT\ChatCAT_Begin\app\index.js:11:11)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
(node:17592) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Related
How can I read this log.log file?
It currently console.log's:
{"type":"Buffer","data":[65,116,116,101,109,112,116,101,100,32,116,111,32,100,105,118,105,100,101,32,98,121,32,122,101,114,111,46,10]}
const displayLogFile = () => {
fs.readFile("./log.log", (err, file) => { //adding "utf-8" only logs a small portion of the .log file, but I was told this might be an async issue.
console.log(file);
});
};
log.log (local file):
Attempted to divide by zero.
Error: ENOENT: no such file or directory, open './NoFileNamedThis.txt'
at Object.openSync (fs.js:498:3)
at Object.readFileSync (fs.js:394:35)
at fileDoesNotExist (C:\Users.js:33:6)
at Object.<anonymous> (C:\Users:54:3)
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 {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: './NoFileNamedThis.txt'
}
Index was outside the bounds of the array.
TypeError: Cannot read property '0' of null
at arrayIsNull (C:\Users:44:6)
at Object.<anonymous> (C:\Users:66:3)
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
I would like to console.log() this .log, log file, but it console.log()'s an array buffer.
You're not specifying an encoding, so the file gets read as a Buffer.
If no encoding is specified, then the raw buffer is returned.
If options is a string, then it specifies the encoding:
readFile('/etc/passwd', 'utf8', callback);
const displayLogFile = () => {
fs.readFile("./log.log", "utf8", (err, file) => {
console.log(file);
});
};
to have it decoded into a string (assuming it's encoded in UTF-8).
I am new to nodejs and trying to write this web scraper where I am getting the following errors. It asks to return promise however I tried but nothing works out. Not sure if I am using the right packages. Promises in async is quite difficult to understand for me at this point. Any explanation along with the code will be really apprciated.
PS C:\Users\farid\Desktop\Node Projects\webscraping> node --trace-warnings .\index.js (node:10748) UnhandledPromiseRejectionWarning: RequestError: Error: Invalid URI "0"
at new RequestError (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\errors.js:14:15)
at Request.plumbing.callback (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\plumbing.js:87:29)
at Request.RP$callback [as _callback] (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\plumbing.js:46:31)
at self.callback (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:185:22)
at Request.emit (events.js:315:20)
at Request.init (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:273:17)
at Request.RP$initInterceptor [as init] (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\configure\request2.js:45:29)
at new Request (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:127:8)
at request (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\index.js:53:10)
at C:\Users\farid\Desktop\Node Projects\webscraping\index.js:13:26
at Object.<anonymous> (C:\Users\farid\Desktop\Node Projects\webscraping\index.js:50:3)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
(node:10748) RequestError: Error: Invalid URI "0"
at new RequestError (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\errors.js:14:15)
at Request.plumbing.callback (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\plumbing.js:87:29)
at Request.RP$callback [as _callback] (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\plumbing.js:46:31)
at self.callback (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:185:22)
at Request.emit (events.js:315:20)
at Request.init (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:273:17)
at Request.RP$initInterceptor [as init] (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\configure\request2.js:45:29)
at new Request (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:127:8)
at request (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\index.js:53:10)
at C:\Users\farid\Desktop\Node Projects\webscraping\index.js:13:26
at Object.<anonymous> (C:\Users\farid\Desktop\Node Projects\webscraping\index.js:50:3)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
(node:10748) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
PS C:\Users\farid\Desktop\Node Projects\webscraping>
Here is my index.js file code.
const request = require("request-promise");
const cheeri = require("cheerio");
const fs = require("fs")
const json2csv = require("json2csv").Parser;
const web_urls = ["https://www.gillmanacura.com/" , "https://www.gillmanacura.com/service/contact-service/"];
// const web_urls = ["https://www.fernandezhonda.com/trade-in-calculator/"];
(async() => {
let emptyData = [];
for(let web_url in web_urls){
let resp = await request({
uri: web_url,
headers:{},
timeout:10000,
json: true,
gzip: true
});
let $ = cheeri.load(resp)
let title = $('head title').text()
let desc = $('meta[name="description"]').attr('content')
let canonical = $('link[rel="canonical"]').attr('href')
let kwd = $('meta[name="keywords"]').attr('content')
let ogTitle = $('meta[property="og:title"]').attr('content')
let ogImage = $('meta[property="og:image"]').attr('content')
let ogkeywords = $('meta[property="og:keywords"]').attr('content')
emptyData.push({
title,
desc,
canonical,
kwd,
ogTitle,
ogImage,
ogkeywords
});
}
const j2csv = new json2csv()
const csv = j2csv.parse(emptyData)
fs.writeFileSync("./results.csv", csv, "utf-8");
})();
How can I resolve these errors? Please advise.
Use for of instead of in. in will iterate over the keys and of over the values.
for(let web_url in web_urls){
I am facing an issue while running my compile.js file using node compile.js .
My code:
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const provider = new HDWalletProvider(
'nut plug quality level uncle jeans retire guide eagle gossip cluster sudden',
'https://rinkeby.infura.io/v3/37097b2064214600912ad8a746ff433a'
);
const web3 = new Webs(provider);
const deploy = async (() => {
const accounts = await (web3.eth.Accounts());
console.log('Attempting to deploy from account', accounts[0]);
const result = await(new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!'] })
.send({gas: '1000000', from: accounts[0]})
);
console.log('contract deployed to', result.options.address);
});
deploy();
After running : node compile.js
Error log:
/home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js:38
async awaitCurrentBlock () {
^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
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.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/edureka/sankalp_practice/inbox/node_modules/web3-provider-engine/index.js:4:25)
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.require (module.js:497:17)
I did my analysis and it seems that "const HDWalletProvider = require('truffle-hdwallet-provider');" is calling for function async awaitCurrentBlock () in /home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js.
So please let me know how to resolve it.
system: Ubuntu
version of node: v6.11.4
version of npm : 5.4.2
your dependency uses "async awaitCurrentBlock" that looks like node 8.* in which case you're simply using too old version of node. You want that dependency, then you have to update, but that will break your code in another way -> you're importing dependencies "async" and "await" which are reserved keywords in Node 8, so you'll have to update your syntax too
I try to deploy nuxt project using the latest version of Nuxt which is nuxt-edge to firebase. This is my function code.
const { Nuxt } = require('nuxt-edge')
const express = require('express')
const functions = require('firebase-functions')
const app = express()
const config = {
dev: false,
buildDir: 'nuxt',
build: {
extractCSS: true,
cache: false,
parallel: true,
publicPath: '/assets/'
}
}
const nuxt = new Nuxt(config)
const handleRequest = (req, res) => {
return new Promise((resolve, reject) => {
nuxt.render(req, res, promise => {
promise.then(resolve).catch(reject)
})
})
}
app.use(handleRequest)
exports.jefrydcossr = functions.https.onRequest(app)
It successfully run locally with firebase serve --only hosting,function command. But when I deployed it online and I open the hosting url, I got server error 500.
After I looked at the error log, I got error like this
2018-06-14T12:43:26.094Z D jefrydcossr: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error: only one instance of babel-polyfill is allowed
at Object.<anonymous> (/user_code/node_modules/nuxt-edge/node_modules/babel-polyfill/lib/index.js:10:9)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/node_modules/nuxt-edge/dist/nuxt-legacy.js:50:1)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
2018-06-14T12:43:26.206Z E jefrydcossr: undefined
2018-06-14T12:51:04.440Z N jefrydcossr: undefined
2018-06-14T12:53:28.052Z N jefrydcossr: undefined
The repository of this project here https://github.com/jefrydco/jefrydco-id
i am trying to connect to mysql server (host : localhost) through node.js, i am really new to node.js and i have no idea on how to do this, please help!!!
current code which i am using to connect to the server
var client = require('socket.io').listen(8080).sockets,
mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'testDatabase',
port : '3306'
});
connection.connect();
var strQuery = 'select * from users';
connection.query( strQuery, function(err, rows){
if(err){
throw err;
}else{
console.log(rows);
}
});
connection.end();
which apparently gives the below error
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'prashanthsun9'#'localhost
' (using password: YES)
at Handshake.Sequence._packetToError (C:\wamp\www\node_chat\js\node_modules\
mysql\lib\protocol\sequences\Sequence.js:30:14)
at Handshake.ErrorPacket (C:\wamp\www\node_chat\js\node_modules\mysql\lib\pr
otocol\sequences\Handshake.js:99:18)
at Protocol._parsePacket (C:\wamp\www\node_chat\js\node_modules\mysql\lib\pr
otocol\Protocol.js:205:24)
at Parser.write (C:\wamp\www\node_chat\js\node_modules\mysql\lib\protocol\Pa
rser.js:62:12)
at Protocol.write (C:\wamp\www\node_chat\js\node_modules\mysql\lib\protocol\
Protocol.js:37:16)
at Socket.<anonymous> (C:\wamp\www\node_chat\js\node_modules\mysql\lib\Conne
ction.js:73:28)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
--------------------
at Protocol._enqueue (C:\wamp\www\node_chat\js\node_modules\mysql\lib\protoc
ol\Protocol.js:110:48)
at Protocol.handshake (C:\wamp\www\node_chat\js\node_modules\mysql\lib\proto
col\Protocol.js:42:41)
at Connection.connect (C:\wamp\www\node_chat\js\node_modules\mysql\lib\Conne
ction.js:99:18)
at Object.<anonymous> (C:\wamp\www\node_chat\js\server.js:11:12)
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)
at startup (node.js:119:16)
Please help, please help!!!
Your connection is not yet setup when you try your query.
To debug, change this line:
connection.connect();
to
connection.connect(function(err, conn) {
if(err) {
console.log('MySQL connection error: ', err);
process.exit(1);
}
});
So you'll get the error trace of why your connection is not ok.
Try to upgrade your npm mysql version to ^2.1.1.