I'm wondering what would be the best route to populate a MySQL database with querys I pull from a script using express and node js.
The script I'm running on port 3000 looks like this:
curl localhost:3000/register?name=bob\&width=13.970000\&time=0
curl localhost:3000/wheels?left=0.000000\&right=0.000000\&time=0 --cookie "USER=bob"
curl localhost:3000/echo?dist=9.220000\&time=10 --cookie "USER=bob"
curl localhost:3000/line?l1=1\&l2=1\&l3=1\&time=20 --cookie "USER=bob"
curl localhost:3000/other?ir=0\&time=30 --cookie "USER=bob"
curl localhost:3000/wheels?left=3.000000\&right=3.000000\&time=100 --cookie "USER=bob"
curl localhost:3000/echo?dist=9.220000\&time=110 --cookie "USER=bob"
curl localhost:3000/line?l1=1\&l2=1\&l3=1\&time=120 --cookie "USER=bob"
curl localhost:3000/other?ir=0\&time=130 --cookie "USER=bob"
curl localhost:3000/wheels?left=3.000000\&right=3.000000\&time=200 --cookie "USER=bob"
curl localhost:3000/echo?dist=9.220000\&time=210 --cookie "USER=bob"
curl localhost:3000/line?l1=1\&l2=1\&l3=1\&time=220 --cookie "USER=bob"
My app.js file looks like this:
const express = require('express');
const cookieParser = require('cookie-parser');
const mysql = require('mysql');
let app = express()
app.use(cookieParser());
var pool = mysql.createPool( {
host: 'localhost',
user: 'root',
password: 'root',
database: 'cars',
connectionLimit: 10,
multipleStatements : true
});
app.get('/register', function(req, res) {
mysql.pool.query("INSERT INTO todo (`name`) VALUES (?)", [name], function( err, results ) {
if (err)
throw err
response.send(results);
})
});
app.listen(3000, function(req, res) {
console.log('Express JS ready for port 3000');
});
My database is set up in phpMyAdmin and looks like this: My database using phpMyAdmin
When I run the script on port 3000, the error I keep getting is:
TypeError: Cannot read property 'query' of undefined
Eventually I want to populate the MySQL database using /wheels, /line, /echo, etc.. but the more I mess with it the more I get similar errors. Anyone see where I might be going wrong or can point me in the right as to where I might learn how to properly do something like this? Thanks
name) VALUES (?)", [req.query.name], function( err, results ) I also changed mysql db to be not strict