运行Azure函数时找不到mssql节点js包

时间:2019-08-20 11:14:57

标签: node.js sql-server azure-functions azure-app-service-plans azure-functions-core-tools

我正在尝试在本地azure函数中连接SQL Server, 并且出现以下错误,

[error] Worker was unable to load function timerTriggerWithEventHub: 'Error: Cannot find module 'mssql''

但是我已经在计算机上安装了mssql软件包,

这是我的代码,

const sql = require('mssql').Request;
module.exports = async function (context, myTimer) {
    var config = {
        user: 'sa',
        password: 'Gain@123',
        server: 'DESKTOP-J7IPQ7H', 
        database: 'RealTimeProductSales' 
    };
    sql.connect(config, function (err) {    
        if (err) console.log(err);
        // create Request object
        var request = new Request();           
        // query to the database and get the records
        request.query('select * from dbo.ProdTC', function (err, recordset) {            
            if (err) console.log(err)
            console.log(recordset)
            // send records as a response
            // res.send(recordset);

        });
    });

    // console.log('saranraj')
    // console.log(context,myTimer)
    // var timeStamp = new Date().toISOString();

    // if (myTimer.IsPastDue)
    // {
    //     context.log('JavaScript is running late!');
    // }
    // context.log('JavaScript timer trigger function ran!', timeStamp);   
    // return "{'name':'saran'}"
};

当我安装软件包时,我会得到这样的输出

npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\SivaSakthiVelan\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\SivaSakthiVelan\package.json'
npm WARN SivaSakthiVelan No description
npm WARN SivaSakthiVelan No repository field.
npm WARN SivaSakthiVelan No README data
npm WARN SivaSakthiVelan No license field.

+ mssql@5.1.0
updated 1 package and audited 11650 packages in 6.832s
found 226 vulnerabilities (42 moderate, 184 high)
  run `npm audit fix` to fix them, or `npm audit` for details

1 个答案:

答案 0 :(得分:0)

似乎package.json丢失了。

您可以尝试运行以下命令:

npm init -f

上面的命令将帮助您初始化package.json(-f表示强制)。

您可以在package.json中检查依赖项。

然后运行以下命令:

npm install mssql