0

I want to use use tedious in my Azure web app to follow this tutorial https://learn.microsoft.com/en-us/azure/sql-database/sql-database-connect-query-nodejs I get the error "Uncaught Error: Module name "tedious" has not been loaded yet" with require('tedious').Connection. How do I load this module in Azure?

The javascript code:

var Connection = require('tedious').Connection;
var Request = require('tedious').Request;



// Create connection to database
var config = {
  userName: '******', // update me
  password: '*****', // update me
  server: '*******', // update me
  options: {
      database: 'signals' //update me
  }
}
var connection = new Connection(config);

// Attempt to connect and execute queries if connection goes through
connection.on('connect', function(err) {
    if (err) {
        console.log(err)
    }
    else{
        queryDatabase()
    }
});

function queryDatabase(){
    console.log("test");
    console.log("test");
    console.log('Reading rows from the Table...');

    // Read all rows from table
    request = new Request(
        "SELECT * FROM signals",
        function(err, rowCount, rows) {
            console.log(rowCount + ' row(s) returned');
        }
    );

    request.on('row', function(columns) {
        columns.forEach(function(column) {
            console.log("%s\t%s", column.metadata.colName, column.value);
        });
    });

    connection.execSql(request);
} 
Rik Smits
  • 63
  • 9

1 Answers1

2

How do I load this module in Azure?

In Azure, you can install Node.js module through Kudu Debug Console which could be accessed via https://<your-web-app-name>.scm.azurewebsites.net/DebugConsole

  1. cd to D:\home\site\wwwroot in the console.

  2. run the following command inside the wwwroot directory: npm install tedious

enter image description here

Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
  • I get the error: "D:\home\site\wwwroot>npm install tedious D:\home `-- tedious@2.0.0 npm D:\home\site\wwwroot> WARN enoent ENOENT: no such file or directory, open 'D:\home\package.json' npm WARN home No description npm WARN home No repository field. npm WARN home No README data npm WARN home No license field." – Rik Smits May 24 '17 at 07:31
  • It seems that there is no `package.json` in your app's root folder. You can run the command `npm init` to create a `package.json` file to it. – Aaron Chen May 24 '17 at 07:49
  • I created the package.json. When I do npm install tedious I get "D:\home\site\wwwroot> WARN wwwroot@1.0.0 No description npm WARN wwwroot@1.0.0 No repository field." – Rik Smits May 24 '17 at 08:10
  • Actually, they are the warnings, don't worry about them. See [here](https://stackoverflow.com/questions/16827858/npm-warn-package-json-no-repository-field). If you can find the `tedious` folder in `node_modules`, it means that you load this module properly. – Aaron Chen May 24 '17 at 08:21
  • Well I still get the "Uncaught Error: Module name "tedious" has not been loaded yet." in the browser console even though I restarted the server. – Rik Smits May 24 '17 at 08:24
  • Could you edit your question with some code you have written? – Aaron Chen May 24 '17 at 08:31
  • Are you attempting to require tedious module in client-side JavaScript rather than Node.js? – Aaron Chen May 24 '17 at 08:42
  • No I dont want it to load on the client side but on the Azure web app side. – Rik Smits May 24 '17 at 08:46
  • Is the code you provided above included in HTML file or Node.js route? – Aaron Chen May 24 '17 at 08:54
  • In the html file – Rik Smits May 24 '17 at 09:07
  • We can't require `tedious` module in browser-side Javascript because this is a Node.js module. You should include the code in server-side instead. – Aaron Chen May 24 '17 at 09:29
  • Thanks. I will try that – Rik Smits May 24 '17 at 09:34