Answer the question
In order to leave comments, you need to log in
Setting up a site loaded on VPS hosting?
There is such an application, it works without errors, but records are not displayed from the database
. The error is most likely in connecting to the database, although it did not display any errors on the console, because I probably don't catch them. Maybe someone will improve my code to catch connection errors, but everything works fine on the local server.
The application works as a server. I don’t even understand what’s wrong, because everything works fine on localhost.
var express = require('express');
var app = express();
var path = require('path');
var formidable = require('formidable');
var fs = require('fs');
var mysql=require('mysql');
var con=mysql.createConnection({
host: 'automaps.by',
port:81,
user: 'root',
password:'root',
database: 'automaps'
});
var bodyParser=require('body-parser');
var jsonParser=bodyParser.json();
var hbs =require('hbs');
app.use(express.static(__dirname+'/'));
app.post('/', jsonParser, function(req,res){
if (!req.body) {
return res.sendStatus(400);
}
var reqText=req.body.text;
var bodyRes={
text: reqText
}
console.log(reqText);
con.query('SELECT * from services where keywords LIKE ?','%' + reqText + '%',function (err, servicesQuery) {
if (err) throw err;
bodyRes=servicesQuery;
console.log(bodyRes);
res.send(bodyRes);
});
});
app.post('/autowash', jsonParser, function(req,res){
if (!req.body) {
return res.sendStatus(400);
}
var reqText=req.body.text;
var bodyRes={
text: reqText
}
console.log(reqText);
con.query('SELECT * from services where keywords LIKE ?','%' + reqText + '%',function (err, servicesQuery) {
if (err) throw err;
bodyRes=servicesQuery;
console.log(bodyRes);
res.send(bodyRes);
});
});
app.get('/get', jsonParser, function(req,res){
if (!req.body) {
return res.sendStatus(400);
}
var reqText=req.body.text;
var bodyRes={
text: reqText
}
console.log(reqText);
con.query('SELECT * from services',function (err, servicesQuery) {
if (err) throw err;
bodyRes=servicesQuery;
console.log(bodyRes);
res.send(bodyRes);
});
});
app.set('view engine', 'hbs');
app.get('/admin', function(req,res){
res.render('admin.hbs');
});
app.get('/autowash', function(req,res){
res.render('autowash.hbs');
});
app.get('/autoservice', function(req,res){
res.render('autoservice.hbs');
});
app.get('/deteyling-centr', function(req,res){
res.render('deteyling-centr.hbs');
});
app.get('/shinomontage', function(req,res){
res.render('shinomontage.hbs');
});
var server = app.listen(80,"178.172.173.78",function(){
console.log('Server listening on port 80');
});
Answer the question
In order to leave comments, you need to log in
Has the vps base been created? And why is mysql connecting on port 81? When it defaults to 3306
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question