I work on a site with angular 2 and node.js and I'm try to connect my BDD with a JS script but when I call my script in my html file I've got the error : Uncaught ReferenceError: require is not defined. I'm new in angular 2 and in web but I can't see why I've got this error. this is my code.
connexionsql.js :
var mysql = require('mysql');
var con = mysql.createConnection({
host : "127.0.0.1",
user : "root",
password : "",
database : "hope_to"
});
connection.connect(function(err) {
if (err) throw err;
con.query("SELECT nb_annee_experience FROM annee_experience", function (err, result) {
if (err) throw err;
console.log(result);
});
});
index.html :
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HOPE TO</title>
<base href="/">
<nav>
<a href="#"> <img src="C:\wamp64\www\angular2-seed-master\hopetotest.jpg" alt=""> </a>
|
<a href="connexion/connexion.html"> Connexion </a>
</nav>
</head>
<body>
<app>Loading...</app>
<script async src="main.bundle.js"></script>
<script src="connexionsql.js"></script>
</body>
</html>
via ugo scelles
No comments:
Post a Comment