Created
April 13, 2017 20:33
-
-
Save Kamilnaja/311272dcaed7f3f1e2dea9baa45c629e to your computer and use it in GitHub Desktop.
login to mysql from express.app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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