Answer the question
In order to leave comments, you need to log in
Data not updating when added to Mysql database via PhpMyAdmin in NodeJS?
Please tell me how to make it so that when data changes in the Mysql database (for example, adding, deleting and editing), these changes are displayed without restarting the Nodejs server. Here is my application code
var express = require('express');
var mysql = require('mysql');
var bodyParser = require('body-parser');
var app = express();
var transliterate = require('transliteration');
app.set('view engine', 'ejs');
var urlencodedParser = bodyParser.urlencoded({ extended: false });
//Коннект к базе данных
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'social'
});
//END Коннект к базе данных
connection.connect();
var query = connection.query('SELECT * FROM `users` ', function(error, result){
if(error) throw error;
app.get('/users', function(req, res){
res.render('users', { users:result});
});
app.get('/users/:id', function(req, res){
var user = result[req.params.id-1];
res.render('user', { user:user});
});
});
connection.end();
app.get('/', function(req, res){
//res.sendFile(__dirname + "/index.html");
res.render('index');
});
app.get('/form', function(req, res){
//res.sendFile(__dirname + "/index.html");
res.render('form');
});
app.post('/form', urlencodedParser, function(req, res){
console.log(req.body);
//res.sendFile(__dirname + "/index.html");
res.render('spasibo', {name:req.body.name});
});
Answer the question
In order to leave comments, you need to log in
a query to the database must be done with each request to /users or /users/:id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question