Skip to content

Instantly share code, notes, and snippets.

@eppsteve
Created November 2, 2016 20:18
Show Gist options
  • Select an option

  • Save eppsteve/c3450fff8a9a595d28f037d05f30a18d to your computer and use it in GitHub Desktop.

Select an option

Save eppsteve/c3450fff8a9a595d28f037d05f30a18d to your computer and use it in GitHub Desktop.
var express = require('express');
var app = express();
var sql = require("mssql"); //load the driver
// config for your database
var config = {
user: 'sa',
password: 'mypassword',
server: 'localhost',
database: 'SchoolDB'
};
app.get('/', function (req, res) {
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from Student', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
});
var server = app.listen(5000, function () {
console.log('Server is running..');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment