<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dileepa Mabulage</title>
    <description>The latest articles on DEV Community by Dileepa Mabulage (@dileepamabulage).</description>
    <link>https://dev.to/dileepamabulage</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F997771%2Fbec63c8f-c138-4faf-93f9-93383d10e776.jpg</url>
      <title>DEV Community: Dileepa Mabulage</title>
      <link>https://dev.to/dileepamabulage</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dileepamabulage"/>
    <language>en</language>
    <item>
      <title>Uploading Images to a Sails.js Server: A Quick Guide</title>
      <dc:creator>Dileepa Mabulage</dc:creator>
      <pubDate>Mon, 18 Sep 2023 05:01:07 +0000</pubDate>
      <link>https://dev.to/dileepamabulage/uploading-images-to-a-sailsjs-server-a-quick-guide-2laj</link>
      <guid>https://dev.to/dileepamabulage/uploading-images-to-a-sailsjs-server-a-quick-guide-2laj</guid>
      <description>&lt;p&gt;Hi All,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mF454-fZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3840/1%2Al-UrKxnt-irZdlQVbdsTZg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mF454-fZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3840/1%2Al-UrKxnt-irZdlQVbdsTZg.png" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Greetings everyone! In this comprehensive guide, we will walk you through the process of uploading image files to a Sails.js server, deploying the application on Render.com, and accessing the uploaded images via the deployed URL. So, let’s dive right in!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Setup the Sailsjs server
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install Sails
&lt;/h3&gt;

&lt;p&gt;To kick things off, install Sails by running the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install sails g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Create your app
&lt;/h3&gt;

&lt;p&gt;Generate a new Sails app by navigating to your desired directory and executing:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sails new test-project --no-frontend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For our purposes, we’re focusing solely on the server component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure Sailsjs routes
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Run this command in the CLI&lt;/p&gt;

&lt;p&gt;sails generate action image-upload&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Run the following command in your CLI to create a controller file in the api/controllersfolder:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Within the image-uplod.js` file, add the following input configuration after the description:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;images: {&lt;br&gt;
          type: 'ref',&lt;br&gt;
          description: 'Uploaded file stream',&lt;br&gt;
          required: true,&lt;br&gt;
     },&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;After the description add this.&lt;/p&gt;

&lt;p&gt;files: ['images'],&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Following this, add the ‘files’ property with ‘images’ as the value, indicating that this controller will handle image uploads.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add this try-catch block inside fn to check the API is working.&lt;/p&gt;

&lt;p&gt;try {&lt;br&gt;
      return exits.success("Success Response");&lt;br&gt;
 } catch (error) {&lt;br&gt;
      return exits.error(error);&lt;br&gt;&lt;br&gt;
 }&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now the image-upload.js file will look like this.&lt;/p&gt;

&lt;p&gt;module.exports = {&lt;br&gt;
  friendlyName: "Image upload",&lt;/p&gt;

&lt;p&gt;description: "",&lt;/p&gt;

&lt;p&gt;files: ["images"],&lt;/p&gt;

&lt;p&gt;inputs: {},&lt;/p&gt;

&lt;p&gt;exits: {},&lt;/p&gt;

&lt;p&gt;fn: async function (inputs, exits) {&lt;br&gt;
    try {&lt;br&gt;
      return exits.success("Success Response");&lt;br&gt;
    } catch (error) {&lt;br&gt;
      return exits.error(error);&lt;br&gt;&lt;br&gt;
    }&lt;br&gt;
  },&lt;br&gt;
};&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Update the startscript in package.json to the following and then install cross-envusing npm i cross-env&lt;/p&gt;

&lt;p&gt;"start": "cross-env NODE_ENV=production node app.js",&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Update the sockets inside of the config/env/production.js&lt;/p&gt;

&lt;p&gt;onlyAllowOrigins: [&lt;br&gt;
      '&lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;'&lt;br&gt;
 ],&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Otherwise you can use sails lift it to up the server.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u_ebiav6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AXgt6tmMvRrluoP4KTTCYmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u_ebiav6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AXgt6tmMvRrluoP4KTTCYmg.png" alt="server running" width="567" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setup the routes inside config/routes.js&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;setup the route as &lt;a href="http://localhost:1337/api/v1/image-upload" rel="noopener noreferrer"&gt;http://localhost:1337/api/v1/image-upload&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports.routes = {
  'POST /api/v1/image-upload': 'image-upload'
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Re-run the server and make a POST API request to the &lt;a href="http://localhost:1337/api/v1/image-upload" rel="noopener noreferrer"&gt;http://localhost:1337/api/v1/image-upload&lt;/a&gt; endpoint using Postman.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j4feZOJu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AqZX1JmVAPPYEJh4pWm8DYA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j4feZOJu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AqZX1JmVAPPYEJh4pWm8DYA.png" alt="Success API response" width="647" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure Image Upload Code
&lt;/h3&gt;

&lt;p&gt;Now our route is working perfectly.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install the skipper npm npm i skipper and enable it inside the config/http.js . Add the maxTimeToBuffer image size limit settings to the bodyParserconfiguration, like this. max limit is restricted uploading files over 10 MB.&lt;/p&gt;

&lt;p&gt;bodyParser: (function _configureBodyParser(){&lt;br&gt;
      var skipper = require('skipper');&lt;br&gt;
      var middlewareFn = skipper({ strict: true, maxTimeToBuffer: 1000000 , limit: '10mb' });&lt;br&gt;
      return middlewareFn;&lt;br&gt;
    })(),&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Navigate to image-upload.js and add the inputs section to specify image handling:&lt;/p&gt;

&lt;p&gt;inputs: {&lt;br&gt;
    images: {&lt;br&gt;
      type: 'ref',&lt;br&gt;
      description: 'Uploaded file stream',&lt;br&gt;
      required: true,&lt;br&gt;
    },&lt;br&gt;
  },&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Replace the try-catch block within the fn function with code to handle image uploads:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  try {

       inputs.images.upload(
        {
          dirname: require('path').resolve(
            sails.config.appPath,
            'assets/images',
          ),

        },
        (err, uploadedFiles) =&amp;gt; {
          if (err) {
            return this.res.serverError(err)
          };

          return exits.success({
            message: uploadedFiles.length + ' file(s) uploaded successfully!',
            files: uploadedFiles,
          });
        },
      );


    } catch (error) {
      return exits.error(error);      
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;All the uploaded images will be saved in the assests/iamges folder.&lt;/p&gt;

&lt;p&gt;Finally, image-upload.js the file looks like this.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {&lt;br&gt;
  friendlyName: "Image upload",

&lt;p&gt;description: "",&lt;/p&gt;

&lt;p&gt;files: ["images"],&lt;/p&gt;

&lt;p&gt;inputs: {&lt;br&gt;
    images: {&lt;br&gt;
      type: 'ref',&lt;br&gt;
      description: 'Uploaded file stream',&lt;br&gt;
      required: true,&lt;br&gt;
    },&lt;br&gt;
  },&lt;/p&gt;

&lt;p&gt;exits: {},&lt;/p&gt;

&lt;p&gt;fn: async function (inputs, exits) {&lt;br&gt;
    try {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   inputs.images.upload(
    {
      dirname: require('path').resolve(
        sails.config.appPath,
        'assets/images',
      ),

    },
    (err, uploadedFiles) =&amp;amp;gt; {
      if (err) {
        return this.res.serverError(err)
      };

      return exits.success({
        message: uploadedFiles.length + ' file(s) uploaded successfully!',
        files: uploadedFiles,
      });
    },
  );


} catch (error) {
  return exits.error(error);      
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;},&lt;br&gt;
};&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Image upload to server&lt;br&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Re-run the server and make a POST request with image form data using Postman.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5NEBEnA4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AglzqhD6Xtul5j0U3bql0ow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5NEBEnA4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AglzqhD6Xtul5j0U3bql0ow.png" alt="changing file type" width="584" height="322"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ensure you set the key type to filein the form data. You can select one or more images for upload.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5q1q-X5d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AG6lGycffCc5a6RhY4S3S0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5q1q-X5d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AG6lGycffCc5a6RhY4S3S0w.png" alt="image upload API response" width="800" height="718"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will receive 200 responses and images will be uploaded inside the assest/images folder with unique names.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f3hBH-FR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A-9AJJi2HSmIt6Q036PhXug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f3hBH-FR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A-9AJJi2HSmIt6Q036PhXug.png" alt="uploaded images" width="451" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;To assign custom names to uploaded images, add the following code segment inside the upload method:&lt;/p&gt;

&lt;p&gt;saveAs(file, cb) {&lt;br&gt;
    let ext = file.filename.split('.').pop();&lt;br&gt;
    cb(null, &lt;code&gt;${file.filename}_${Date.now()}.${ext}&lt;/code&gt;);&lt;br&gt;
  },&lt;/p&gt;

&lt;p&gt;{&lt;br&gt;
  dirname: require('path').resolve(&lt;br&gt;
    sails.config.appPath,&lt;br&gt;
    'assets/images',&lt;br&gt;
  ),&lt;br&gt;
  saveAs(file, cb) {&lt;br&gt;
    let ext = file.filename.split('.').pop();&lt;br&gt;
    cb(null, &lt;code&gt;${file.filename}_${Date.now()}.${ext}&lt;/code&gt;);&lt;br&gt;
  },&lt;br&gt;
},&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This will result in images having custom names.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--84Y8czCY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AP3QnAxWpFswwcLlWXjFJCA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--84Y8czCY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AP3QnAxWpFswwcLlWXjFJCA.png" alt="images with custom name" width="451" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have finished the image upload section.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Make sure to rerun the server everytime after changing the code, otherwise install nodemon npm i nodemon and run nodemon app.js nodemon will catch the code changes and automatically rerun the server.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Access uploaded images via the URL
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Edit .sailsrc and add the public path:&lt;/p&gt;

&lt;p&gt;"paths": {&lt;br&gt;
    "public": "assets"&lt;br&gt;
  }&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MufxwCVv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AzZqJAzno9ZEpxwgwL6sD9w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MufxwCVv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AzZqJAzno9ZEpxwgwL6sD9w.png" alt=".sailsrc file" width="316" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Re-run the server and access the images via URLs like:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://localhost:1337/images/$%7Bimage_name_with_extension%7D" rel="noopener noreferrer"&gt;http://localhost:1337/images/${image_name_with_extension}&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;examples:- &lt;br&gt;
  &lt;a href="http://localhost:1337/images/user.png_1694411326047.png" rel="noopener noreferrer"&gt;http://localhost:1337/images/user.png_1694411326047.png&lt;/a&gt;&lt;br&gt;
  &lt;a href="http://localhost:1337/images/c91d3cf8-9018-4aa1-86f8-499b22e3ba84.png" rel="noopener noreferrer"&gt;http://localhost:1337/images/c91d3cf8-9018-4aa1-86f8-499b22e3ba84.png&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v5JMUptX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3842/1%2AdZ1K6ErTcQNWXjpari1uWA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v5JMUptX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3842/1%2AdZ1K6ErTcQNWXjpari1uWA.png" alt="locally uploaded image" width="800" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Deploy the Web Application in Render
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Add assets/** to .gitignore folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Update the package.json , add a new build script.&lt;/p&gt;

&lt;p&gt;"scripts": {&lt;br&gt;
    "start": "cross-env NODE_ENV=production node app.js",&lt;br&gt;
    "build": "npm install",&lt;br&gt;
    "test": "npm run lint &amp;amp;&amp;amp; npm run custom-tests &amp;amp;&amp;amp; echo 'Done.'",&lt;br&gt;
    "lint": "./node_modules/eslint/bin/eslint.js . --max-warnings=0 --report-unused-disable-directives &amp;amp;&amp;amp; echo '✔  Your .js files look good.'",&lt;br&gt;
    "custom-tests": "echo \"(No other custom tests yet.)\" &amp;amp;&amp;amp; echo"&lt;br&gt;
  },&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;3 . Initialize the git repository and push the code to git.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an account &lt;a href="https://render.com" rel="noopener noreferrer"&gt;https://render.com&lt;/a&gt; and create a web service.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ps-7eHob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Awr06NslFXJCdZrcg1sbvbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ps-7eHob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Awr06NslFXJCdZrcg1sbvbg.png" alt="create web service" width="270" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Build and deploy from a Git repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure your account choose the correct GitHub repository and connect.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure the web app.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tes5CtT9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3350/1%2ARyebLyxuq1VAOfbCL95UVg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tes5CtT9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3350/1%2ARyebLyxuq1VAOfbCL95UVg.png" alt="Web app configuration 1" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1K7jr7hA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3304/1%2AV90-MRH3WKG8zmBizycxHw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1K7jr7hA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3304/1%2AV90-MRH3WKG8zmBizycxHw.png" alt="Web app configuration 2" width="800" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Set up your web app configuration, choosing a free instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create the web service, and you’ll see the deployment terminal in action&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m4LBwanK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3306/1%2ANMc1txTYa8lHdq22q4lmeg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m4LBwanK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3306/1%2ANMc1txTYa8lHdq22q4lmeg.png" alt="web service terminal" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Monitor the progress on the Render.com dashboard.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E10XR8h4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2490/1%2A1BM2F1r29ll2OGhyLBNt3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E10XR8h4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2490/1%2A1BM2F1r29ll2OGhyLBNt3g.png" alt="the dashboard view" width="800" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once the deployment is successful, you’re ready to proceed!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7iCMYJ9q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2664/1%2AL6rI2Kzn10gaSsnBwkZTzA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7iCMYJ9q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2664/1%2AL6rI2Kzn10gaSsnBwkZTzA.png" alt="Deployed Webapp" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Upload images to the deployed web app
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Copy the deployed web app URL.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oG9tVgDS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AYQ9Ul5MIRm-BeM5FfzXDBw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oG9tVgDS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AYQ9Ul5MIRm-BeM5FfzXDBw.png" alt="Webapp deployed URL" width="565" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Replace the Postman localhost URL with this new URL and make a POST request to upload images.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5gGyB86E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A6IEU4tk-aF10BqklOk226A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5gGyB86E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A6IEU4tk-aF10BqklOk226A.png" alt="Success API response" width="800" height="863"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should receive a successful API response, indicating the images have been uploaded.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To view the uploaded images via the URL&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Retrieve the image names from the response files and append them to the server URL to access the images.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;URLs will resemble:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sailsjs-image-upload.onrender.com/images/$%7Bimage_name_with_extension%7D" rel="noopener noreferrer"&gt;https://sailsjs-image-upload.onrender.com/images/${image_name_with_extension}&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;examples:- &lt;br&gt;
  &lt;a href="https://sailsjs-image-upload.onrender.com/images/user.png_1694418912994.png" rel="noopener noreferrer"&gt;https://sailsjs-image-upload.onrender.com/images/user.png_1694418912994.png&lt;/a&gt;&lt;br&gt;
  &lt;a href="https://sailsjs-image-upload.onrender.com/images/user.png_1694418912996.png" rel="noopener noreferrer"&gt;https://sailsjs-image-upload.onrender.com/images/user.png_1694418912996.png&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C9nXhXPB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2822/1%2Am1J3nthJUGejhQRLu9NMFA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C9nXhXPB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2822/1%2Am1J3nthJUGejhQRLu9NMFA.png" alt="View the deployed image via the URL" width="800" height="537"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! You’ve successfully set up image uploading in your Sails.js server, deployed the application on Render.com&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J5VFkyaf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AZpnyYxpATFEbXD2c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J5VFkyaf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AZpnyYxpATFEbXD2c.png" width="515" height="193"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You….
&lt;/h2&gt;

&lt;p&gt;You can find the code &lt;a href="https://github.com/dsmabulage/sailsjs-image-upload" rel="noopener noreferrer"&gt;Repository URL&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to see what I am working on? Check out my &lt;a href="https://github.com/dsmabulage" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to connect? Reach out to me on &lt;a href="https://www.linkedin.com/in/dileepa-mabulage-8334b3213/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>sails</category>
      <category>image</category>
    </item>
    <item>
      <title>Creating AWS CloudWatch Logs using .NET Console Application: A Step-by-Step Guide</title>
      <dc:creator>Dileepa Mabulage</dc:creator>
      <pubDate>Fri, 10 Mar 2023 03:57:10 +0000</pubDate>
      <link>https://dev.to/dileepamabulage/creating-aws-cloudwatch-logs-using-net-console-application-a-step-by-step-guide-2a1m</link>
      <guid>https://dev.to/dileepamabulage/creating-aws-cloudwatch-logs-using-net-console-application-a-step-by-step-guide-2a1m</guid>
      <description>&lt;p&gt;Welcome to a comprehensive guide on creating AWS CloudWatch Logs using a .NET Console Application. In this article, we will go through the process of setting up CloudWatch and logging events from a .NET Console Application. Whether you are new to AWS or a seasoned user, this guide will provide you with a clear understanding of how to monitor and manage your application logs in the AWS Cloud. Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create IAM Client in AWS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate IAM Client Credentials&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure AWS CloudWatch&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create .Net Console Application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add appsettings.json file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access values inside appsettings.json file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure AWS Cloudwatch in Console App&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CloudWatch Log Stream&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Create IAM Client in AWS
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Identity and Access Management (IAM) is a web service for securely controlling access to Amazon Web Services services. With IAM, you can centrally manage users, security credentials such as access keys, and permissions that control which Amazon Web Services resources users and applications can access.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Login to &lt;a href="https://console.aws.amazon.com" rel="noopener noreferrer"&gt;amazon&lt;/a&gt; with credentials&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From home select your preferred region&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AfURAyj0xGI4Am1YCpaEwZg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AfURAyj0xGI4Am1YCpaEwZg.png" alt="AWS Console Home Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AOQFzTXKNXVoFbESVPr3NQA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AOQFzTXKNXVoFbESVPr3NQA.png" alt="Region selection list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An AWS region is &lt;strong&gt;a cluster of data centers in a specific geographic area&lt;/strong&gt;, such as the Northeastern United States or Western Europe. It is advisable to choose a region that is geographically close to users. This reduces latency because the data reaches the users more quickly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Go to IAM Services page&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3784%2F1%2AKJ7KCac9nXjs9Tv7TSZk1Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3784%2F1%2AKJ7KCac9nXjs9Tv7TSZk1Q.png" alt="IAM Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Select Users from the left Access management panel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click Add Users&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter username =&amp;gt; Next&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select Attach Policies Directly in Permission Options&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select CloudWatchFullAccess from Permission Policies&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AjwJAORaCPKWaevyYgE5vGQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AjwJAORaCPKWaevyYgE5vGQ.png" alt="Set Permissions to IAM Client"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3686%2F1%2AncWsv6j3zb9Oti-F7oIerg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3686%2F1%2AncWsv6j3zb9Oti-F7oIerg.png" alt="IAM client Creation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Next =&amp;gt; Create User&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3054%2F1%2ALA2KHSkFAjV-qxqWv2NSkw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3054%2F1%2ALA2KHSkFAjV-qxqWv2NSkw.png" alt="Created client"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now you can see the created IAM User&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2. Generate IAM Client Credentials
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on the created IAM user&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to security credentials&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2918%2F1%2AqfKFMnMQ5m_LTzxTRigadQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2918%2F1%2AqfKFMnMQ5m_LTzxTRigadQ.png" alt="Generate keys for client"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scroll down to Access Keys&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2252%2F1%2AqP8jB-HGhhX38lSlyn5zUg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2252%2F1%2AqP8jB-HGhhX38lSlyn5zUg.png" alt="Generate keys for client"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create access key =&amp;gt; select other =&amp;gt; Next&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2558%2F1%2A2OrmPLrfoh67toTRdiUwAw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2558%2F1%2A2OrmPLrfoh67toTRdiUwAw.png" alt="Configure access key permission"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create an access key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy both the access key and the Secret access key for later use&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2832%2F1%2Arexm6vl0vyIJHeXUiWgDiA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2832%2F1%2Arexm6vl0vyIJHeXUiWgDiA.png" alt="Access key and secret key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Done&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3. Configure AWS CloudWatch
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;CloudWatch Logs enable you to centralize the logs from all of your systems, applications, and AWS services that you use, in a single, highly scalable service. You can then easily view them, search them for specific error codes or patterns, filter them based on specific fields, or archive them securely for future analysis.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate CloudWatch in AWS Services&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to Log groups in the left panel (Make sure you have selected the correct AWS region)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3648%2F1%2A2SXqENTHpF2kW0t3g3B9Cg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3648%2F1%2A2SXqENTHpF2kW0t3g3B9Cg.png" alt="AWS CloudWatch logGroups"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Click on create Log group&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A CloudWatch Log Group is a container for log streams, which are collections of log events that share the same source. For example, you could create a log group for logs generated by an application, and then create separate log streams for each instance of the application.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter a suitable name and set the expiry date&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2194%2F1%2AEp7HXjmRrV387ZjPHqKbEg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2194%2F1%2AEp7HXjmRrV387ZjPHqKbEg.png" alt="Log group Creation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3008%2F1%2AVOCqZHkcktglUSyBqkorOw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3008%2F1%2AVOCqZHkcktglUSyBqkorOw.png" alt="Successfully created logGroup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to Log Group&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a Log Stream&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A CloudWatch Log Stream is a sequence of log events that share the same source. Within a log group, each log stream has a unique name and stores events independently. You can view and search the log events in a stream, set up alarms to be triggered by specific patterns in the log data, and export the log data to other services for further analysis.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2368%2F1%2A8j6C9blTYjXduvCfCmsmkQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2368%2F1%2A8j6C9blTYjXduvCfCmsmkQ.png" alt="LogStream Creation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enter log Stream Name =&amp;gt; create&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Create .Net Console Application
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Visual Studio&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new project =&amp;gt; Select the console app&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2028%2F1%2AUEeMbnLvahqLWX1czhCr3w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2028%2F1%2AUEeMbnLvahqLWX1czhCr3w.png" alt="Select Console Application of Visual Studio"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Next =&amp;gt; Enter Project name =&amp;gt; Next =&amp;gt; .Net 6.0 =&amp;gt; Create&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2928%2F1%2ARYKAhTUh9E1gyj5xdiQOEA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2928%2F1%2ARYKAhTUh9E1gyj5xdiQOEA.png" alt="Sample code in Console App"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Add appsettings.json file
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The “appsettings.json” file in .NET projects is used to store configuration settings for an application. It allows you to store key-value pairs that represent various configuration options such as database connection strings, API keys, and other application-specific settings.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Right-click on testAwsConsoleApp =&amp;gt; Add =&amp;gt; New item&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3668%2F1%2A_UL-I073x6a5Bb8a06xjRw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3668%2F1%2A_UL-I073x6a5Bb8a06xjRw.png" alt="Add appsettings.json file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search json in the search box&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2356%2F1%2A2LR1Y3GRk7jq0GQxsHHWkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2356%2F1%2A2LR1Y3GRk7jq0GQxsHHWkg.png" alt="File type selection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Select json file and set the name to appsessings.json =&amp;gt; Add&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add this code to appsettings.json file&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    {
      "Client_id": "&amp;lt;your client Id&amp;gt;",
      "Client_secret": "&amp;lt;Your client secret&amp;gt;",
      "LogGroupName": "&amp;lt;Log group name&amp;gt;",
      "LogStreamName": "&amp;lt;Log stream name&amp;gt;",
    }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3684%2F1%2A6pLt6iv2_2tB2RYyls75yQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3684%2F1%2A6pLt6iv2_2tB2RYyls75yQ.png" alt="Code on appsettings.json file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click appsettings.json file on the solution explorer and set its Copy to Output Directory value to Copy always&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A8qS1nhZZXzEoPsSgE9nLCw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A8qS1nhZZXzEoPsSgE9nLCw.png" alt="appsettings.json file configuration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Access values inside appsettings.json file
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to Program.cs file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove all the sample code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paste this code&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    using Microsoft.Extensions.Configuration;

    namespace testAwsConsoleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                IConfigurationBuilder configBuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
                IConfiguration configuration = configBuilder.Build();
                Console.WriteLine(configuration["Client_id"]);
            }
        }
    }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Install these Nuget packages from Nuget package manager&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2928%2F1%2AcQtP2ql0aNgYsdtl16t9Qg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2928%2F1%2AcQtP2ql0aNgYsdtl16t9Qg.png" alt="Nuget package manager"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run the program Ctrl + F5 or green triangle on the top&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AtYwIxMY1H6PzOERj2sP7ug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AtYwIxMY1H6PzOERj2sP7ug.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now we can access the appsettings.json values from our code&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  7. Configure AWS Cloudwatch in Console App
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Create a new c# class AWSCloudWatch.cs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ai9ryZFTy9hXb8ziLIbxRWg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ai9ryZFTy9hXb8ziLIbxRWg.png" alt="Add new c# class"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Select the class and set the name to AWSCloudWatch.cs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3560%2F1%2ATkjWlQOIUL4b5dYI3zGwXw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3560%2F1%2ATkjWlQOIUL4b5dYI3zGwXw.png" alt="AWSCloudWatch.cs file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install this Nuget package&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AfLqRfEY54-VzUjdF4ehh4g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AfLqRfEY54-VzUjdF4ehh4g.png" alt="AWSSDK Nuget package"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Paste this code in AWSCloudWatch.cs
&amp;gt;  In RegionEndpoint make sure you select the accurate region in which you create the log group and log stream&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    using Amazon.CloudWatchLogs;
    using Amazon.CloudWatchLogs.Model;
    using Microsoft.Extensions.Configuration;

    namespace testAwsConsoleApp
    {
        public class AWSCloudWatch
        {
            private readonly IConfiguration _configuration;
            private static System.Timers.Timer aTimer;

            public AWSCloudWatch(IConfiguration configuration)
            {
                _configuration = configuration;
            }

            public void TimerStart()
            {
                Console.WriteLine("\nPress the Enter key to exit the application...\n");
                Console.WriteLine("The application started at {0:HH:mm:ss.fff}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                aTimer = new System.Timers.Timer(4000); // method executes every 4 seconds
                aTimer.Elapsed += (s, e) =&amp;gt; CloudWatchLog();
                aTimer.AutoReset = true;
                aTimer.Enabled = true;
                Console.ReadLine();
                aTimer.Stop();
                aTimer.Dispose();
                Console.WriteLine("Terminating the application...");

                while (Console.Read() != 'q') ;

            }

            public async void CloudWatchLog()
            {
                try
                {
                    var credentials = new Amazon.Runtime.BasicAWSCredentials(_configuration["Client_id"], _configuration["Client_secret"]);

                    var config = new AmazonCloudWatchLogsConfig
                    {
                        RegionEndpoint = Amazon.RegionEndpoint.APSoutheast1
                    };

                    var logClient = new AmazonCloudWatchLogsClient(credentials, config);

                    await logClient.PutLogEventsAsync(new PutLogEventsRequest()
                    {
                        LogGroupName = _configuration["LogGroupName"],
                        LogStreamName = _configuration["LogStreamName"],
                        LogEvents = new List&amp;lt;InputLogEvent&amp;gt;()
                        {
                            new InputLogEvent()
                            {
                                Message = "error message from console app",
                                Timestamp = DateTime.UtcNow
                            }
                        }

                    });
                    Console.WriteLine("Logging successfull");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message, "Error occured");
                }

            }
        }
    }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here we created a timer for cloud watch log execution and set the log as error message from console app . The timer calls the CloudWatchLog function every 4 seconds.&lt;/p&gt;

&lt;p&gt;And you can set up custom error messages as well as API call error messages as InputLogEvent message. So you can log the API error messages to AWS cloudwatch.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Complete Program.cs code&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    using Microsoft.Extensions.Configuration;

    namespace testAwsConsoleApp
    {
        class Program
        {        
            static void Main(string[] args)
            {
                IConfigurationBuilder configBuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
                IConfiguration configuration = configBuilder.Build();

                var cloudwatchParam = new AWSCloudWatch(configuration);

                cloudwatchParam.TimerStart();
            }

        }
    }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Run the program&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AEpxK4qMsPbDBD2v0J3qylA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AEpxK4qMsPbDBD2v0J3qylA.png" alt="Console Application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8. CloudWatch Log Stream
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to your cloud watch log stream&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2980%2F1%2Ad1Hebn3ohIvfL0tXef2rUw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2980%2F1%2Ad1Hebn3ohIvfL0tXef2rUw.png" alt="Inside log stream"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are all the logs that we send from .Net console application&lt;/p&gt;

&lt;h3&gt;
  
  
  Source Code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/DSmabulage/CloudWatch_ConsoleApp" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Thank you….
&lt;/h3&gt;

</description>
      <category>javascript</category>
      <category>cloudwatch</category>
      <category>aws</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Access Azure KeyVault Secrets Through Nodejs Application</title>
      <dc:creator>Dileepa Mabulage</dc:creator>
      <pubDate>Mon, 30 Jan 2023 04:27:16 +0000</pubDate>
      <link>https://dev.to/dileepamabulage/access-azure-keyvault-secrets-through-nodejs-application-bim</link>
      <guid>https://dev.to/dileepamabulage/access-azure-keyvault-secrets-through-nodejs-application-bim</guid>
      <description>&lt;p&gt;Azure Key Vault is a cloud-based service that allows users to securely store and manage sensitive information, such as passwords, keys, and certificates. This allows for a more secure and efficient way to manage and access sensitive information in a cloud environment.&lt;/p&gt;

&lt;p&gt;In this article, we will discuss how to access these secrets through a Node.js application. We will cover how to set up an Azure Key Vault, how to authenticate with it, and how to retrieve and use the secrets in your application. By the end of this article, you will have a better understanding of how to use Azure Key Vault to secure and manage your application's sensitive information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create Nodejs server&lt;/li&gt;
&lt;li&gt;Create Azure Key Vault&lt;/li&gt;
&lt;li&gt;Add secrets to key Vault&lt;/li&gt;
&lt;li&gt;Add secrets from CLI&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to5#-register-app-in-azure-active-directory"&gt;Register app in Azure Active Directory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Add Access Policies to key Vault&lt;/li&gt;
&lt;li&gt;Reveal secrets in Nodejs application&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Create Nodejs server
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create the directory and run &lt;code&gt;npm init -y&lt;/code&gt; in the command prompt&lt;/li&gt;
&lt;li&gt;Open that directory in VSCode using typing &lt;code&gt;code .&lt;/code&gt; in the command prompt&lt;/li&gt;
&lt;li&gt;Open vs code terminal and install the following
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express --save 
npm install nodemon --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Nodemon is a tool that automatically restarts a Node.js application when changes are made to the code. This can save developers time and effort by eliminating the need to manually stop and start the application each time a change is made.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an index.js file and paste the following code
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) =&amp;gt; {
  res.send('Hello World!');
});

app.listen(port, () =&amp;gt; {
  console.log(`Example app listening on port ${port}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvcyy2gy1hkiqr5nrsm16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvcyy2gy1hkiqr5nrsm16.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In your terminal (which should be in the project directory), type &lt;code&gt;nodemon index.js&lt;/code&gt; and hit the Enter button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8scljtuw440uyq8imgbj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8scljtuw440uyq8imgbj.png" alt="Image description" width="776" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open a new tab in postman or any web browser and the address bar, type &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;, and hit the Enter button&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlydqm6jgona4sk0vdzs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlydqm6jgona4sk0vdzs.png" alt="Image description" width="386" height="142"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb5nsk0hzxyhp5ylxf1y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb5nsk0hzxyhp5ylxf1y.png" alt="Image description" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the Node server is up and running...&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Create Azure key vault
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Sign in to the Azure portal at &lt;a href="https://portal.azure.com" rel="noopener noreferrer"&gt;https://portal.azure.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To set up a Key Vault in Azure:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the Azure portal and select "Create a resource" from the menu or Home page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search for "Key Vault" and select it from the results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on "Create" in the Key Vault section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the "Create key vault" section, enter a unique name for the vault (e.g. "nodejsazurekeyvault") &lt;em&gt;A vault's name must be between 3-24 alphanumeric characters. The name must begin with a letter, end with a letter or digit, and not contain consecutive hyphens&lt;/em&gt;, select a subscription and create a new resource group.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pick a location and keep the other options unchanged.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on "Create" to finalize the setup.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7k0618pvdy1vd0ojxx3l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7k0618pvdy1vd0ojxx3l.png" alt="Image description" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Add secrets to key Vault
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Click secrets in the left panel&lt;/li&gt;
&lt;li&gt;Click Generate/Import at top of the page&lt;/li&gt;
&lt;li&gt;Add a secret name, and value&lt;/li&gt;
&lt;li&gt;Toggle enables to yes&lt;/li&gt;
&lt;li&gt;Click Create&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fou8iae6r7bro7wyz6ogf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fou8iae6r7bro7wyz6ogf.png" alt="Image description" width="800" height="709"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhz4w5tvy2cvicj1nwitz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhz4w5tvy2cvicj1nwitz.png" alt="Image description" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Add secrets from CLI
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install Azure CLI &lt;a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli" rel="noopener noreferrer"&gt;Download&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Run these commands in the PowerShell window
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;az login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;az keyvault secret set --vault-name "&amp;lt;your-unique-keyvault-name&amp;gt;" --name "MultilineSecret" --file "secretfile.txt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9ajb8k2qqfex2s6nj7w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9ajb8k2qqfex2s6nj7w.png" alt="Image description" width="698" height="142"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuuio7szqpw882r4girio.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuuio7szqpw882r4girio.png" alt="Image description" width="800" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Register the app in Azure Active Directory
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to Azure Active Directory&lt;/li&gt;
&lt;li&gt;Click App registrations on the left panel&lt;/li&gt;
&lt;li&gt;Click New Registration&lt;/li&gt;
&lt;li&gt;Enter the app name and platform to Web&lt;/li&gt;
&lt;li&gt;Register&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu10kkm1480vjznt2sy9q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu10kkm1480vjznt2sy9q.png" alt="Image description" width="800" height="613"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgdn894zewkbeu5evjv5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgdn894zewkbeu5evjv5l.png" alt="Image description" width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click certificates and secrets&lt;/li&gt;
&lt;li&gt;New client's secret&lt;/li&gt;
&lt;li&gt;Add a description and set the expiry date&lt;/li&gt;
&lt;li&gt;Add&lt;/li&gt;
&lt;li&gt;Copy the value and keep it for future&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F77lzjhnyn3buzal9rjx9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F77lzjhnyn3buzal9rjx9.png" alt="Image description" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw82rfpzcbc2b7m44jtvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw82rfpzcbc2b7m44jtvg.png" alt="Image description" width="800" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Add app to key Vault
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the Key Vault&lt;/li&gt;
&lt;li&gt;Click Access Policies in the left panel&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If access policies don't appear. Navigate to access configuration and select vault access policy. And apply.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fca7quutgfjrsgsjlbhn6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fca7quutgfjrsgsjlbhn6.png" alt="Image description" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create &lt;/li&gt;
&lt;li&gt;Select Secret Management from the template dropdown&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F86dskparw5xvivtp27of.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F86dskparw5xvivtp27of.png" alt="Image description" width="800" height="602"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Next&lt;/li&gt;
&lt;li&gt;Select keyvaultapp&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszwe0s85g00mx30doz8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszwe0s85g00mx30doz8d.png" alt="Image description" width="800" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Next&lt;/li&gt;
&lt;li&gt;Create&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  7. Reveal secrets in Nodejs application
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to index.js&lt;/li&gt;
&lt;li&gt;Open vs code terminal and install the following
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @azure/identity
npm install @azure/keyvault-secrets
npm install dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a &lt;code&gt;.ENV&lt;/code&gt; file and add the following code
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;KEYVAULT_URI=&amp;lt;"key vault URL"&amp;gt;
AZURE_TENANT_ID=&amp;lt;"registered app in azure active directory"&amp;gt;
AZURE_CLIENT_ID=&amp;lt;"registered app in azure active directory"&amp;gt;
AZURE_CLIENT_SECRET=&amp;lt;"previously copied value"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpcbx2qjpdhcte0tww51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpcbx2qjpdhcte0tww51.png" alt="Image description" width="800" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmvm4as53x6bkg13cdgtt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmvm4as53x6bkg13cdgtt.png" alt="Image description" width="800" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbfky9wxng65uymgcrt3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbfky9wxng65uymgcrt3.png" alt="Image description" width="800" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add this code to index.js
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require("dotenv").config();
const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const credential = new DefaultAzureCredential();
const client = new SecretClient(process.env.KEYVAULT_URI, credential);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a separate route and add this code (single line secret)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get("/secret", (req, res) =&amp;gt; {
  client
    .getSecret("testsecret")
    .then((data) =&amp;gt; {
      res.send(data.value);
    })
    .catch((error) =&amp;gt; {
      console.log(error);
      res.send(error);
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In your terminal (which should be in the project directory), type &lt;code&gt;nodemon index.js&lt;/code&gt; and hit the Enter button.&lt;/li&gt;
&lt;li&gt;Open a new tab in postman or any web browser and the address bar, type &lt;a href="http://localhost:3000/secret" rel="noopener noreferrer"&gt;http://localhost:3000/secret&lt;/a&gt;, and hit the Enter button&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz7wgo1l20kz94mbsy0n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz7wgo1l20kz94mbsy0n.png" alt="Image description" width="542" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ehuf72od1k9tf9fxxcp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ehuf72od1k9tf9fxxcp.png" alt="Image description" width="800" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a separate route and add this code (multi-line secret)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get("/multilinesecret", (req, res) =&amp;gt; {
  client
    .getSecret("MultilineSecret")
    .then((data) =&amp;gt; {
      const parsedSecret = JSON.parse(data.value);
      res.json(parsedSecret);
    })
    .catch((error) =&amp;gt; {
      console.log(error);
      res.send(error);
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In your terminal (which should be in the project directory), type &lt;code&gt;nodemon index.js&lt;/code&gt; and hit the Enter button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open a new tab in postman or any web browser and the address bar, type &lt;a href="http://localhost:3000/multilinesecret" rel="noopener noreferrer"&gt;http://localhost:3000/multilinesecret&lt;/a&gt;, and hit the Enter button&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvagvy9ca0id1vd9tbjh3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvagvy9ca0id1vd9tbjh3.png" alt="Image description" width="547" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foytvhnxhkldbd97y57yv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foytvhnxhkldbd97y57yv.png" alt="Image description" width="800" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Complete Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const app = express();
const port = 3000;

require("dotenv").config();
const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const credential = new DefaultAzureCredential();
const client = new SecretClient(process.env.KEYVAULT_URI, credential);

app.get("/", (req, res) =&amp;gt; {
  res.send("Hello World!");
});

app.get("/secret", (req, res) =&amp;gt; {
  client
    .getSecret("testsecret")
    .then((data) =&amp;gt; {
      res.send(data.value);
    })
    .catch((error) =&amp;gt; {
      console.log(error);
      res.send(error);
    });
});

app.get("/multilinesecret", (req, res) =&amp;gt; {
  client
    .getSecret("MultilineSecret")
    .then((data) =&amp;gt; {
      const parsedSecret = JSON.parse(data.value);
      res.json(parsedSecret);
    })
    .catch((error) =&amp;gt; {
      console.log(error);
      res.send(error);
    });
});

app.listen(port, () =&amp;gt; {
  console.log(`Example app listening on port ${port}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Source Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/DSmabulage/AzureKeyVault_NodeJs" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;

</description>
      <category>extensions</category>
      <category>opensource</category>
      <category>tooling</category>
    </item>
  </channel>
</rss>
