31

このサンプル プロジェクトを Azure 関数としてビルドしようとしていますが、いくつかのパッケージが必要ですhttps://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-App-only

https://azure.microsoft.com/en-us/documentation/articles/functions-reference/#nodejavascript-apiを使用して NodeJS Azure Functions でパケット管理を使用できることがわかります

これを使ってみた

var request = require('request');

この文

You can include packages in your function directory (i.e. via npm install) and then import them to your function in the usual ways (i.e. via require('packagename'))

そこで、C# Azure 関数が使用するように、これを含む project.json を作成しました。

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "chalk": "^1.1.1",
        "q": "^1.4.1",
        "request": "^2.67.0"
      }
    }
  }
}

このエラーが発生します

2016-04-06T19:49:42.026 Exception while executing function: Functions.MicrosoftGraphWebHookNode. mscorlib: One or more errors occurred. Error: Cannot find module 'request'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (D:\home\site\wwwroot\MicrosoftGraphWebHookNode\index.js:1:77)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17).

project.json は機能しますか?

4

2 に答える 2

43

package.json関数ディレクトリに を含めて、 npm installKudu または Azure portal のコンソールを使用して Node.js プロジェクトで通常行うように実行できます。

詳細については、 https ://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=v2#dependency-management をご覧ください。

于 2016-04-06T22:19:26.880 に答える
-1

同様のことを行ったところ、SendGrid を使用せずに SMTP が機能しました。以下は、azure関数の私のコードです。

const nodemailer = require('nodemailer');
module.exports = async function (context, myTimer) {

let transport = nodemailer.createTransport({
    host: '',
    port: 2525,
    auth: {
       user: '',
       pass: ''
    }
});


const message = {
    from: '', // Sender address
    to: '',         // List of recipients
    subject: '', // Subject line
    text: '' // Plain text body
};

transport.sendMail(message, function(err, info) {
    if (err) {
      console.log(err)
    } else {
      console.log(info);
    }
});

};

于 2019-10-31T12:44:00.777 に答える