Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------- db.js -------*/
- var mysql = require('mysql');
- var connection = mysql.createConnection({
- host: 'localhost',
- user: 'root',
- password: '********',
- database: 'MyDatabase'
- });
- module.exports.getInfo = function getInfo(cb) {
- var sql = 'SELECT * FROM MyTable;';
- connection.query(sql, cb)
- }
- /*------- index.js --------*/
- var db = require('./db');
- var express = require('express');
- router.get('/', function (req, res) {
- db.getInfo(function (err, rows) {
- if (err)
- console.log(err);
- res.render('index', {
- title: 'Index',
- model: rows
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment