0

I am actually involved in a POC and looking to build a web app which can display SQL results after hitting a button. Got to know that seriate node.js is a good platform for this. But unable to find out how to link these components. Any help towards this would be appreciable.

Mohit Sudhera
  • 341
  • 1
  • 4
  • 16

1 Answers1

1

You can check the below code

var webconfig = {
    user: 'login',
    password: 'sa@123',
    server: 'localhost', 
    database: 'TestDB',

    options: {
        encrypt: false // Use this if you're on Windows Azure 
    }
}

var express = require('express');
var sql = require('mssql');
var http = require('http');

var app = express();
var port = process.env.PORT || 8000;

var connection = new sql.Connection(webconfig, function(err) {
    var request = new sql.Request(connection); 
    request.query('select * from Users', function(err, recordset) {
       if(err)      // ... error checks 
            console.log('Database connection error');

    console.dir("User Data: "+recordset);
    });
});


app.listen(port);
console.log(port+' is the magic port');
Supraj V
  • 967
  • 1
  • 10
  • 19
  • `module.js:340 throw err; ^ Error: Cannot find module 'mssql' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object. (/home/msudhera/check.js:13:11) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) ` – Mohit Sudhera May 15 '17 at 14:18
  • got this error after executing.I was running earlier with seriate and the query ran with but it was not related to UI `var sql = require("seriate"); var config = { "server":"localhost", "user": "username", "password":"xyz", "database":"DBname", }; sql.setDefaultConfig( config ); sql.execute({ query:"select * from job"}).then( function(results){ console.log(results); }, function(err){ console.log("Something bas happened:", err); }); ` – Mohit Sudhera May 15 '17 at 14:24
  • Yes, I just installed mssql, http, tedious. It was asking for these modules. now getting the error: /mssql/lib/tedious.js:109 index, ^ **SyntaxError: Unexpected token ,** at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) in inbuilt tedious.js. Not sure with what to replace the comma. – Mohit Sudhera May 15 '17 at 14:57