<?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: Sanjula De Alwis</title>
    <description>The latest articles on DEV Community by Sanjula De Alwis (@sanjulad).</description>
    <link>https://dev.to/sanjulad</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%2F383637%2F20c1c1f7-e33e-495b-90e3-86064b08b7d1.jpeg</url>
      <title>DEV Community: Sanjula De Alwis</title>
      <link>https://dev.to/sanjulad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanjulad"/>
    <language>en</language>
    <item>
      <title>Weather Application using Node.js ❄️</title>
      <dc:creator>Sanjula De Alwis</dc:creator>
      <pubDate>Mon, 11 May 2020 05:39:44 +0000</pubDate>
      <link>https://dev.to/sanjulad/weather-application-using-node-js-44e6</link>
      <guid>https://dev.to/sanjulad/weather-application-using-node-js-44e6</guid>
      <description>&lt;h1&gt;Before the application build lets talk about what is Node.js?&lt;/h1&gt;

&lt;p&gt;Node.js is a JavaScript run time environment. Sounds great, but what does that mean? How does that work?&lt;br&gt;
The Node run-time environment includes everything you need to execute a program written in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Why Node.js?&lt;b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt; Here’s a formal definition as given on the official Node.js website:
Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Table of Contents :&lt;/b&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install NodeJS&lt;/li&gt;
&lt;li&gt;Getting API&lt;/li&gt;
&lt;li&gt;Consuming API&lt;/li&gt;
&lt;li&gt;Show API&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--raz6m8Dm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/875/0%2A6-chlaP2EwqR0_sF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--raz6m8Dm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/875/0%2A6-chlaP2EwqR0_sF.png" alt="nodejs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Cool! Lets Start the project 🙌&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;1.Open a command prompt and type:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir weatherApp&lt;br&gt;
cd weatherApp&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;These commands are universal for whatever OS you’ll be running. The former will create a new directory inside the directory you are currently in, mkdir = “make directory”. The latter will change into this newly created directory, cd = “change directory”. Hard-core windows users can calm down, this will work for you guys too, as it is equivalent to creating a new folder within your file system… only more fancy.&lt;/p&gt;

&lt;p&gt;2.Initialize your project and link it to &lt;a href="https://www.npmjs.com/"&gt; npm &lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;3.Get the Weather API from here.&lt;/p&gt;

&lt;p&gt;This website basically give you the weather based on your city.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e84M82mQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/794/1%2Ad4TFL5evELc0yJHJQzFL4A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e84M82mQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/794/1%2Ad4TFL5evELc0yJHJQzFL4A.png" alt="api"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, What you need is&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Country Name (you can use any country, its up to you!)&lt;/li&gt;
&lt;li&gt;Country Code (Go to this link and get the Code of your country)&lt;/li&gt;
&lt;li&gt;API Key (Sign Up this link and they will give you the API key)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;Cool! It’s time to develop this application 💻&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Now, go back to you project folder(weatherApp) open this project using VS Code or any other IDE you like. Go to the terminal make shuer you are in the right directory eg: …/weatherApp/ .&lt;/p&gt;

&lt;p&gt;Open the terminal and type this below code :&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter all the things. Now your project has package.json file.&lt;/li&gt;
&lt;li&gt;Now create a new file name it app.js.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Go back to the terminal and install certain packages :&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install request -S&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Go to app.js and copy below code :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PiPtqLO7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/875/1%2AiB4hOUKrprpwJv_RDOBZhA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PiPtqLO7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/875/1%2AiB4hOUKrprpwJv_RDOBZhA.jpeg" alt="apicode"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var http = require('http');
var url = 'put here your API Key URL';
var server = http.createServer(function ( request, response ) {
// All logic will go here
var request = require('request');
request( url , function(err, res, body) {
var data = JSON.parse(body);
response.write("&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;div id='container'&amp;gt;");
response.write("&amp;lt;h1&amp;gt;"+'City Name : '+ data['name'] + '&amp;lt;br&amp;gt;'+ "&amp;lt;/h1&amp;gt;");
response.write("&amp;lt;h2&amp;gt;"+'Temperature : '+ data.main['temp'] + '&amp;lt;br&amp;gt;'+ "&amp;lt;/h2&amp;gt;");
response.write("&amp;lt;h2&amp;gt;"+'Sunset Time : '+ new Date(data.sys['sunset']*1000) + '&amp;lt;br&amp;gt;'+ "&amp;lt;/h2&amp;gt;");
response.write("&amp;lt;/div&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");
response.end();
});
}).listen(8081);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Go back to you terminal and run this application :&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You can see the output with your :&lt;/p&gt;

&lt;p&gt;City Name :&lt;br&gt;
Temperature :&lt;br&gt;
Sunset Time :&lt;/p&gt;

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

</description>
      <category>node</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
