This blog post shows how you can deploy a new Node.js application from Visual Studio Team Services or Microsoft Team Foundation Server to Azure App Service.
Code
- Download our Node.js Hello World sample app or Install Node.js Tools for Visual Studio and create a new Node.js application.
- Upload your code to Team Services or your on-premises Team Foundation Server: either push your code to Git or check in your code to TFVC.
Build
- Open your team project in your web browser (If you don’t see your team project listed on the home page, select Browse.)
- On-premises TFS: http://{your_server}:8080/tfs/DefaultCollection/{your_team_project}
- Visual Studio Team Services: https://{your_account}.visualstudio.com/DefaultCollection/{your_team_project}
- Click Empty to start with an empty definition.
- In the repository tab of build definition make sure the repository selected is the one where you pushed (Git) or checked in (TFVC) your code
Add the build steps
On the Tasks or Build tab, add these steps.
Package: npm install | Install your npm package dependencies.
For example, in case of sample app it will be nodejs-express-hello-world-app |
Build: Gulp | Pack your files into a .zip file.
|
Build: Publish Build Artifacts | Publish the build outputs, such as the .zip file as we do in the example below.
|
Enable continuous integration (CI)
On the Triggers tab, enable Continuous integration (CI). This tells the system to queue a build whenever someone on your team commits or checks in new code.
Save, queue, and test the build
Save and queue the build. Once the build is done, click the link to the completed build (for example, Build 1634), click Artifacts, and then click Explore to see the .zip file produced by the build. This is the web deploy package that your release definition will consume to deploy your app.
Release
- Open the Releases tab of the Build & Release hub, open the + drop-down in the list of release definitions, and choose Create release definition
- In the DEPLOYMENT TEMPLATES dialog, select the Azure App Service Deployment template and choose OK.
- Select the build definition you created earlier as the source of artifact to be deployed.
- Configure the Azure App Service Deployment task:
Deploy: Azure App Service Deploy - Azure Subscription: Select a connection from the list under Available Azure Service Connections. If no connections appear, choose Manage, select New Service Endpoint | Azure Resource Manager, and follow the prompts. Then return to your release definition, refresh the Azure Subscription list, and select the connection you just created. Note: If your Azure subscription is defined in an Azure Government Cloud, ensure your deployment process meets the relevant compliance requirements. For more details, see Azure Government Cloud deployments.
- App Service Name: the name of the App Service (the part of the URL without .azurewebsites.net)
- Deploy to Slot: make sure this is cleared (the default)
- Virtual Application : leave blank
- Package or Folder: $(System.DefaultWorkingDirectory)***.zip (the default)
- Advanced:
- Take App Offline: If you run into locked .DLL problems when you test the release, as explained below, try selecting this check box.
- Deployment script: The task gives you additional flexibility to run deployment script on the Azure App Service. For example, you can run a script to update dependencies (node packages) on the Azure App Service instead of packaging the dependencies in the build step.
- Generate web.config: In case you are deploying a Node.js application which was not created by using Node.js Tools for Visual Studio then the task will help you generate the web.config required to run the Node apps on Azure App Service.
This is required because Windows Azure App Service uses iisnode to host Node.js applications in IIS on Windows
- Type a name for the new release definition and, optionally, change the name of the environment from Default Environment to Dev. Also, set the deployment condition on the environment to “Automatically start after release creation”.
- Save the new release definition. Create a new release and verify that the application has been deployed correctly.
Related Topics
- js Tools for Visual Studio helps you develop Node.js applications by providing Visual Studio project templates as well as intellisense, debugging and profiling support.
- Windows Azure App Service use iisnode to host Node.js applications in IIS on Windows.
0 comments