Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var http = require('http');
- var path = require('path');
- //Import mySQL module
- var mysql = require('mysql');
- var app = express();
- var bodyParser = require('body-parser');
- app.use(bodyParser.urlencoded({extended: true}));
- //Connection object using credentials
- var con = mysql.createConnection({
- host: "localhost",
- user: "data",
- password: "database",
- database: "mydb"
- });
- //Connecting to the database
- con.connect(
- function(err){
- if (err) throw err;
- console.log("Database Connected");
- }
- );
- con.end();
- app.use(express.static(path.join(__dirname, '/public')));
- app.get('/', function(req, res) {
- res.sendFile(path.join(__dirname + '/index.html'));
- });
- app.listen(8080);
Add Comment
Please, Sign In to add comment