Build a Node. js and Mongo.DB web app in Azure.Azure Web Apps provides a highly scalable, self patching web hosting service.This tutorial shows how to create a Node.Azure and connect it to a Mongo.DB database. When youre done, youll have a MEAN application Mongo.DB, Express, Angular.MSDN Magazine Issues and Downloads. Download Adobe Flash Player Manually Firefox Homepage . Read the magazine online, download a formatted digital version of each issue, or grab sample code and apps.Workbench User Guide Eclipse platform overview Getting started Basic tutorial The Workbench Editors and views Editors Views.JS, and Node. js running in Azure App Service.For simplicity, the sample application uses the MEAN.What youll learn Create a Mongo.DB database in Azure.Connect a Node. js app to Mongo.TpBbV.jpg' alt='Debug Windows Service Using Console Application Sample' title='Debug Windows Service Using Console Application Sample' />DBDeploy the app to Azure.Update the data model and redeploy the app.Stream diagnostic logs from Azure.Manage the app in the Azure portal.Prerequisites. To complete this tutorial Install Git.D00_ws_2D00_create1.png' alt='Debug Windows Service Using Console Application Sample' title='Debug Windows Service Using Console Application Sample' />Install Node.NPMInstall Gulp. MEAN.Install and run Mongo.DB Community Edition.If you dont have an Azure subscription, create a free account before you begin.Test local Mongo.DBOpen the terminal window and cd to the bin directory of your Mongo.DB installation. You can use this terminal window to run all the commands in this tutorial.Azure Web Apps provides a highly scalable, selfpatching web hosting service.This tutorial shows how to create a Node.Azure and connect it to a MongoDB.Run mongo in the terminal to connect to your local Mongo.DB server. mongo.If your connection is successful, then your Mongo.DB database is already running.If not, make sure that your local Mongo.DB database is started by following the steps at Install Mongo.DB Community Edition.Often, Mongo. DB is installed, but you still need to start it by running mongod.When youre done testing your Mongo.DB database, type CtrlC in the terminal.Create local Node.In this step, you set up the local Node.Clone the sample application.In the terminal window, cd to a working directory.Run the following command to clone the sample repository.Azure Samplesmeanjs.This sample repository contains a copy of the MEAN.It is modified to run on App Service for more information, see the MEAN.README file. Run the application.Run the following commands to install the required packages and start the application.When the app is fully loaded, you see something similar to the following message.MEAN. JS Development Environment.Environment development.Server http 0. Database mongodb localhostmean dev.App version 0. MEAN.JS version 0. Navigate to http localhost 3.Click Sign Up in the top menu and create a test user.The MEAN. js sample application stores user data in the database.If you are successful at creating a user and signing in, then your app is writing data to the local Mongo.DB database. Select Admin Manage Articles to add some articles.To stop Node. js at any time, press CtrlC in the terminal.Launch Azure Cloud Shell.The Azure Cloud Shell is a free Bash shell that you can run directly within the Azure portal.It has the Azure CLI preinstalled and configured to use with your account.Click the Cloud Shell button on the menu in the upper right of the Azure portal.The button launches an interactive shell that you can use to run the steps in this topic Create production Mongo.DBIn this step, you create a Mongo.DB database in Azure.When your app is deployed to Azure, it uses this cloud database.For Mongo. DB, this tutorial uses Azure Cosmos DB.Cosmos DB supports Mongo.DB client connections.Create a resource group.In the Cloud Shell, create a resource group with the az group create command.A resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed.The following example creates a resource group named my.Resource. Group in the West Europe location.Resource. Group location West Europe.You generally create your resource group and the resources in a region near you.To see all supported locations for App Service plans, run the az appservice list locations command.Create a Cosmos DB account.In the Cloud Shell, create a Cosmos DB account with the az cosmosdb create command.In the following command, substitute a unique Cosmos DB name for the lt cosmosdbname placeholder.This name is used as the part of the Cosmos DB endpoint, https lt cosmosdbname.Cosmos DB accounts in Azure.The name must contain only lowercase letters, numbers, and the hyphen character, and must be between 3 and 5.Resource. Group kind Mongo.DB. The kind Mongo.DB parameter enables Mongo.DB client connections.When the Cosmos DB account is created, the Azure CLI shows information similar to the following example.Policy. default. Consistency.Level Session. Interval.In. Seconds 5. Staleness.Prefix 1. Account.Offer. Type Standard.Endpoint https lt cosmosdbname.Policies. lt Output truncated for readability.Connect app to production Mongo.DBIn this step, you connect your MEAN.Cosmos DB database you just created, using a Mongo.DB connection string.Retrieve the database key.To connect to the Cosmos DB database, you need the database key.In the Cloud Shell, use the az cosmosdb list keys command to retrieve the primary key.Resource. Group. The Azure CLI shows information similar to the following example.Master. Key RS4. Cm.Uwz. GRASJPMoc. Evdn.Kmxy. RILC9. BWis.AYh. 3Hq. 4z. BYKr.XQi. SE4pqx. Uch.Be. O4. QRCz. Ut.Okito. Jw. primary.Readonly. Master.Key Hvitsj. IYz. 8Tw.Rm. Iu. PEUAALRwqg.KOz. JUj. W2. 2w.PL2. U8zo. MVh. Gvreg.Bk. Bk. Ld. MTxq.Bg. DETSq. Ztde. FY7h.El. Tg. Master. Key Lu.ZTi. XU4. Pjuuy. GBbv.S1. N9. IRG3oeg. Ir.Ih. 95. U6. VOstf.Jii. Ipw. 3Ifw. SUg.QWSEYM3. Ve. Eyrh.HJ4rn. 3Ci. 0vu. Fq.A. secondary. Readonly.Master. Key Lps. Cicp.VZq. HRy. 7qb. Mgrzb.RKjb. YCw. CKPQRl.Qpg. Re. AOx. Mcgg.Tvx. JFA9. 4f. Ti.Q7xtxpft. TJc. Xkj.Tir. Q0p. T7. QFr.Q. Copy the value of primary.Master. Key. You need this information in the next step.Configure the connection string in your Node.In your local MEAN.Copy the following code into it.Be sure to replace the two lt cosmosdbname placeholders with your Cosmos DB database name, and replace the lt primarymasterkey placeholder with the key you copied in the previous step.The ssltrue option is required because Cosmos DB requires SSL.Save your changes.Test the application in production mode.Run the following command to minify and bundle scripts for the production environment.This process generates the files needed by the production environment.Run the following command to use the connection string you configured in configenvlocal production.NODEENVproduction node server.NODEENVproduction sets the environment variable that tells Node.Node. js server with server.This is how your Node.Azure. When the app is loaded, check to make sure that its running in the production environment.Environment production.Server http 0. Database mongodb lt cosmosdbname lt primarymasterkey lt cosmosdbname.App version 0. MEAN.JS version 0. Navigate to http localhost 8.Click Sign Up in the top menu and create a test user.If you are successful creating a user and signing in, then your app is writing data to the Cosmos DB database in Azure.In the terminal, stop Node.CtrlC. Deploy app to Azure.In this step, you deploy your Mongo.DB connected Node.Azure App Service.Configure a deployment user.In the Cloud Shell, create deployment credentials with the az webapp deployment user set command.A deployment user is required for FTP and local Git deployment to a web app.The user name and password are account level.They are different from your Azure subscription credentials.In the following command, replace lt username and lt password with a new user name and password.The user name must be unique.The password must be at least eight characters long, with two of the following three elements letters, numbers, symbols.If you get a Conflict.Details 4. 09 error, change the username.If you get a Bad Request.Details 4. 00 error, use a stronger password.You create this deployment user only once you can use it for all your Azure deployments.Note. Record the user name and password.You need them to deploy the web app later.Create an App Service plan.In the Cloud Shell, create an App Service plan with the az appservice plan create command.An App Service plan specifies the location, size, and features of the web server farm that hosts your app.You can save money when hosting multiple apps by configuring the web apps to share a single App Service plan.App Service plans define Region for example North Europe, East US, or Southeast AsiaInstance size small, medium, or largeScale count 1 to 2.MPLAB X IDE Developer Help.Click here to edit contents of this page.Click here to toggle editing of individual sections of the page if possible.Watch headings for an edit link when available.Append content without editing the whole page source.Check out how this page has evolved in the past.If you want to discuss contents of this page this is the easiest way to do it.View and manage file attachments for this page.A few useful tools to manage this Site.See pages that link to and include this page.Change the name also URL address, possibly the category of the page.View wiki source for this page without editing.Viewset parent page used for creating breadcrumbs and structured layout.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2017
Categories |