Created
November 2, 2016 20:18
-
-
Save eppsteve/c3450fff8a9a595d28f037d05f30a18d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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