Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning Node.js Development

You're reading from   Learning Node.js Development Learn the fundamentals of Node.js, and deploy and test Node.js applications on the web

Arrow left icon
Product type Paperback
Published in Jan 2018
Publisher Packt
ISBN-13 9781788395540
Length 658 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Andrew Mead Andrew Mead
Author Profile Icon Andrew Mead
Andrew Mead
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Title Page
Packt Upsell
Contributor
Preface
1. Getting Set Up FREE CHAPTER 2. Node Fundamentals – Part 1 3. Node Fundamentals – Part 2 4. Node Fundamentals – Part 3 5. Basics of Asynchronous Programming in Node.js 6. Callbacks in Asynchronous Programming 7. Promises in Asynchronous Programming 8. Web Servers in Node 9. Deploying Applications to Web 10. Testing the Node Applications – Part 1 11. Testing the Node Applications – Part 2 1. Another Book You May Enjoy Index

Weather app with promises


In this section, we'll learn how to use a library that has promises built in. We'll explore the axios library, which is really similar to request. Although, instead of using callbacks as request does, it uses promises. So we don't have to wrap our calls in promises to get that promise functionality. We'll actually be recreating the entire weather app in this section. We'll only have to write about 25 lines of code. We'll go through the entire process: taking the address, getting the coordinates, and then fetching the weather.

Fetching weather app code from the app.js file

To fetch weather app code from the app.js file, we'll duplicate app.js, because we configure yargs in the original app.js file and we'll want to carry the code over to the new project. There's no need to rewrite it. In the weather directory, we'll duplicate app.js, giving it a new name, app-promise.js.

Inside app-promise.js, before we add anything, let's rip some stuff out. We'll be ripping out the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images