## Node js program to connect to SQL server ##
var express = require ('express');
var app = express();
app.get ('/', function (req,res){
var sql = require ("mssql");
// database config
var config = {
user: 'admin',
password: 'admin',
server: 'localhost',
database: 'db'
};
// Database connectivity
sql.connect (config, function (err){
if (err) console.log (err);
//create a request object
var request = new sql.Request();
// database query
request.query (' Select * from student', function (err, record){
res.send (record);
});
});
});
var server = app.listen(3000, function (){
console.log (' Server running ....');
});
No comments:
Post a Comment