Skip to content

Instantly share code, notes, and snippets.

@Kamilnaja
Created April 13, 2017 20:33
Show Gist options
  • Save Kamilnaja/311272dcaed7f3f1e2dea9baa45c629e to your computer and use it in GitHub Desktop.
Save Kamilnaja/311272dcaed7f3f1e2dea9baa45c629e to your computer and use it in GitHub Desktop.
login to mysql from express.app
var express = require('express');
var http = require('http');
var mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'heroes'
});
connection.connect(function(error) {
if (!!error) {
console.log('Error - big ugly problem');
} else {
console.log('Connected');
}
});
app.get('/', function (req, res) {
res.send('hello');
connection.query("SELECT * FROM heroeslist",function (error, rows, fields) {
if (!!error) {
console.log("Error in the query");
} else {
console.log("successfull query");
}
});
});
app.listen(3000, function () {
console.log('running');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment