Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const http = require('http');
- const mysql = require('mysql');
- const con = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "",
- database: "giocodiimmagini"
- });
- con.connect(function (err) {
- if (err) throw err;
- console.log("connected to DB successfully");
- });
- const server = http.createServer(function (req, res) {
- con.query("SELECT i.imgDir FROM image i", function (err, resDB) {
- if (err) throw err;
- res.writeHead(200, {
- "Content-Type": "text/html"
- });
- res.write("<!DOCTYPE html>");
- res.write("<html>");
- res.write("<head>");
- res.write("<title>Pagina Node.js!</title>");
- res.write("</head>");
- res.write("<body>");
- res.write("<p>Sono un paragrafo <strong>HTML</strong>!</p>");
- resDB.forEach(row => {
- // write result row
- res.write("...");
- });
- res.write("</body>");
- res.write("</html>");
- res.end();
- });
- });
- server.listen(8080);
- console.log("Server is listening");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement