JoeKrynn
JoeKrynn

Reputation: 85

azure functions -running npm install on azure portal

This is a how to question, not a problem

I would like use an npm package in my javascript Azure function. How do I get a console in the azure functions portal to run npm install? If there is a better way to reference the npm package, this will answer my question too. A documentation reference with an example of installing the npm package in an Azure function would also be appreciated.

I apologize for this basic question. I am new to both node and azure functions and have enjoyed learning what I have so far, but this simple procedure is eluding me.

Thank you for any help you can give me

Upvotes: 6

Views: 5844

Answers (2)

quine9997
quine9997

Reputation: 834

Assume the function name is function677761


Step1. Open the browser and visit the Kudo console. https://function677761.scm.azurewebsites.net/DebugConsole


Step2. In the toolbar menu select DebugConsole/CMD


Step3. Run the commands:

C:\home>ls

C:\home>cd .\site\wwwroot

C:\home\site\wwwroot>npm i date-and-time

C:\home> ls


Step4. My output is

HttpTrigger1

host.json

node_modules

package-lock.json

package.json


Step5. Now inside the file package.json there is the node.js library date-and-time just installed.

"dependencies": { "date-and-time": "^2.4.2" }


Step6. I can read the file package.json from here.

https://portal.azure.com/#@myemail345.onmicrosoft.com/resource/subscriptions/3877920b-027777-4513-8777a-ca378888917/resourcegroups/group001/providers/Microsoft.Web/sites/function677761/functionsAppFiles

These values are custom. Depend by my account.

myemail345

group001

function677761

3877920b-027777-4513-8777a-ca378888917


Source1. https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal#settings

Section. Manually install extensions .

Source2. https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=v2-v3-v4-export%2Cv2-v3-v4-done%2Cv2%2Cv2-log-custom-telemetry%2Cv2-accessing-request-and-response%2Cwindows-setting-the-node-version

Section. Folder structure

Upvotes: 3

Sajeetharan
Sajeetharan

Reputation: 222522

You can use the KUDU console at https://yourfunctionappname.scm.azurewebsites.net and navigate to the wwwroot folder and install the package that you need!

Here is an article that i wrote to showcase how you can install python packages!

However when you deploy the azure function package.json will have all the dependencies and you dont need to install them separately.

Upvotes: 8

Related Questions