Azure

Azure App Service – Implementing Node.js Internet App

Within the earlier article, we learnt about making a Node.js internet app in Azure utilizing the App Service. On this article, we’ll study implementing the Node.js internet app utilizing the app service in Azure. That is the second article on the Azure App Service article collection.  

  1. Azure App Service – Creating Node.js Internet App 
  2. Azure App Service – Implementing Node.js Internet App 

Now, allow us to study to implement the Node.js Internet app in Azure.  

Step 1 

Observe up the Azure App Service – Creating Node.js Internet App article and create the net app.  

Step 2 

Now, Click on on the Cloud Shell button on the High Menu bar apart of the Search Bar.  

Step 3 

The Bash terminal will now open on the backside.  

Step 4 

Now, run the next instructions. 

cd ~
mkdir helloworld

It will change the terminal to the foundation listing and create a listing named helloworld. You’re free to call the listing every other title however you’ll need to observe up in a while likewise.  

cd helloworld

Now, change the listing and write the next code.  

npm init -y

It will now create a bundle.json file which is able to now arrange for our Node.js software.  

Step 5 

Now, allow us to create an index.js file with the next code. 

contact index.js

Sort the next code within the bash terminal and now, the interactive editor will open up.  

code .

Right here we are able to see, two information. One the index.js and different the bundle.json file 

Step 6 

Open the bundle.json file and make a small change on the “scripts” changing the “check” for “begin”.  

{
  "title": "helloworld",
  ...
  "scripts": {
    "begin": "node index.js"
  },
  ...
}

Now you can reserve it with CTRL + S button.  

Step 7 

Subsequent, open the index.js file and write the next Node.js program to supply a reply textual content for each GET request made within the server.  

const http = require('http');
const server = http.createServer(perform(request, response) {
    response.writeHead(200, {
        "Content material-Sort": "textual content/html"
    });
    response.finish("<html><physique><h1>Hey C# Nook Reader - That is Ojash.</h1></physique></html>");
});
const port = course of.env.PORT || 1337;
server.hear(port);
console.log(`Server working at http://localhost:${port}`);

It will output my message on the port 1337.  

Now, save the file with CTRL + S.  

Step 8 

Now, open one other browser or tab and browse the web site https://shell.azure.com/. 

The terminal will open and now you must change the listing to the helloworld one wil the command under.  

cd ~/helloworld

Subsequent, begin NPM to begin our internet software.  

npm begin

Step 9 

Now, on the first cloud shell, write the next command to browse the net software we created.  

curl http://127.0.0.1:1337/

Observe that on the finish, we have now the identical port we declared on the index.js file.  

Right here, as we run the command, we are able to see the output as follows which is the html code we wrote as a response on the index.js file 

Thus, we have now efficiently applied the Node.js internet software now.  Ultimately, shut the first cloud shell with CTRL + C and likewise shut the secondary shell we opened.  

Conclusion 

Thus, on this article, we learnt to implement the Node.js internet software utilizing the Azure App Service within the Azure Cloud Platform. Within the following articles, we’ll study to deploy and discover extra issues within the App Service.  

Tags
Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close