node-mysql

INSERT INTO fails with node-mysql

故事扮演 提交于 2019-11-27 15:00:52
I am trying to insert some data with node.js. I have written the following code and installed MySQL support via npm, but I failed to INSERT INTO the table. Here is my code: var mysql = require('mysql'); function BD() { var connection = mysql.createConnection({ user: 'root', password: '', host: 'localhost', port: 3306, database: 'nodejs' }); return connection; } app.post("/user/create", function(req, res) { var objBD = BD(); var post = { username: req.body.username, password: req.body.password }; objBD.query('INSERT INTO users VALUES ?', post, function(error) { if (error) { console.log(error

Node.js MySQL Needing Persistent Connection

牧云@^-^@ 提交于 2019-11-27 09:45:42
问题 I need a persistent MySQL connection for my Node web app. The problem is that this happens about a few times a day: Error: Connection lost: The server closed the connection. at Protocol.end (/var/www/n/node_modules/mysql/lib/protocol/Protocol.js:73:13) at Socket.onend (stream.js:79:10) at Socket.EventEmitter.emit (events.js:117:20) at _stream_readable.js:895:16 at process._tickCallback (node.js:415:13) error: Forever detected script exited with code: 8 error: Forever restarting script for 2

Undefined value after returning an array of values from a MySQL query in a different file

醉酒当歌 提交于 2019-11-27 08:46:50
问题 I'm using the Mysql connector because I need to get some data from my database, but I'm having the following issue: I have two files server.js and dbConnection.js and I have a return in the dbConnection.js file which should return an array and it should show it in the server.js file. However, it prints out an undefined array. I don't understand what I'm doing wrong since I also tried to print out the array before reurning it in the dbConnection.js file and it's shown with the data. server.js:

Use promise to process MySQL return value in node.js

半世苍凉 提交于 2019-11-27 05:33:11
问题 I have a python background and is currently migrating to node.js. I have problem adjusting to node.js due to its asynchronous nature. For example, I am trying to return a value from a MySQL function. function getLastRecord(name) { var connection = getMySQL_connection(); var query_str = "SELECT name, " + "FROM records " + "WHERE (name = ?) " + "LIMIT 1 "; var query_var = [name]; var query = connection.query(query_str, query_var, function (err, rows, fields) { //if (err) throw err; if (err) { /

JavaScript classes with getter and setter cause RangeError: Maximum call stack size exceeded

醉酒当歌 提交于 2019-11-27 05:14:51
I am currently experimenting with ECMA6 classes. My current class looks like the following class Player { constructor(id) { this.id = id; this.cash = 350; } get cash() { return this.cash; } set cash(value) { // line 19 this.cash = value; // line 20 } }; When I am now creating a new Object by calling let playerObject = new Player(1); I receive the following error ...\node_modules\mysql\lib\protocol\Parser.js:82 throw err; ^ RangeError: Maximum call stack size exceeded at Player.cash (player.js:19:11) at Player.cash (player.js:20:15) at Player.cash (player.js:20:15) at Player.cash (player.js:20

Express JS 'this' undefined after routing with app.get(..)

假如想象 提交于 2019-11-27 03:28:53
问题 I have a basic Node JS server which is designed to be used as an API, I've created a log and database module and I've started adding other modules to deal with different request types. I'm using Express.js and node-mysql When I visit /v1/group I get the following error - TypeError: Cannot read property 'database' of undefined at Group.getAll (C:\code\javascript\node\api\api\v1\groups.js:12:23) at callbacks (C:\code\javascript\node\api\node_modules\express\lib\router\index.js:161:37) ... So I

node.js, express - executing mysql queries one after another within loops in a synchronous way

大城市里の小女人 提交于 2019-11-27 03:27:14
问题 In my node.js, express app, I am making an ajax call with the superagent middleware. The call fetches database data in a complex array using the node-mysql middleware through quite a few database queries. Before pasting the code, I am trying to explain in words what I am trying to do although the code would suffice to say what it wants to do with the addition that all the asynchronous things inside the first callback should be done in the synchronous way. Explanation: Inside the callback of

MySQL giving “read ECONNRESET” error after idle time on node.js server

懵懂的女人 提交于 2019-11-26 22:24:52
问题 I'm running a Node server connecting to MySQL via the node-mysql module. Connecting to and querying MySQL works great initially without any errors, however, the first query after leaving the Node server idle for a couple hours results in an error. The error is the familiar read ECONNRESET , coming from the depths of the node-mysql module. A stack trace (note that the three entries of the trace belong to my app's error reporting code): Error at exports.Error.utils.createClass.init (D:\home

INSERT INTO fails with node-mysql

折月煮酒 提交于 2019-11-26 16:41:51
问题 I am trying to insert some data with node.js. I have written the following code and installed MySQL support via npm, but I failed to INSERT INTO the table. Here is my code: var mysql = require('mysql'); function BD() { var connection = mysql.createConnection({ user: 'root', password: '', host: 'localhost', port: 3306, database: 'nodejs' }); return connection; } app.post("/user/create", function(req, res) { var objBD = BD(); var post = { username: req.body.username, password: req.body.password

JavaScript classes with getter and setter cause RangeError: Maximum call stack size exceeded

廉价感情. 提交于 2019-11-26 11:26:09
问题 I am currently experimenting with ECMA6 classes. My current class looks like the following class Player { constructor(id) { this.id = id; this.cash = 350; } get cash() { return this.cash; } set cash(value) { // line 19 this.cash = value; // line 20 } }; When I am now creating a new Object by calling let playerObject = new Player(1); I receive the following error ...\\node_modules\\mysql\\lib\\protocol\\Parser.js:82 throw err; ^ RangeError: Maximum call stack size exceeded at Player.cash