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 now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The JavaScript Workshop

You're reading from   The JavaScript Workshop Learn to develop interactive web applications with clean and maintainable JavaScript code

Arrow left icon
Product type Paperback
Published in Nov 2019
Publisher Packt
ISBN-13 9781838641917
Length 802 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (8):
Arrow left icon
Jahred Love Jahred Love
Author Profile Icon Jahred Love
Jahred Love
Alonzo L. Hosford Alonzo L. Hosford
Author Profile Icon Alonzo L. Hosford
Alonzo L. Hosford
Florian Sloot Florian Sloot
Author Profile Icon Florian Sloot
Florian Sloot
Daniel Rosenbaum Daniel Rosenbaum
Author Profile Icon Daniel Rosenbaum
Daniel Rosenbaum
Philip Kirkbride Philip Kirkbride
Author Profile Icon Philip Kirkbride
Philip Kirkbride
Nick Turner Nick Turner
Author Profile Icon Nick Turner
Nick Turner
Gaurav Mehla Gaurav Mehla
Author Profile Icon Gaurav Mehla
Gaurav Mehla
Joseph Labrecque Joseph Labrecque
Author Profile Icon Joseph Labrecque
Joseph Labrecque
+4 more Show less
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Getting to Know JavaScript 2. Working with JavaScript FREE CHAPTER 3. Programming Fundamentals 4. JavaScript Libraries and Frameworks 5. Beyond the Fundamentals 6. Understanding Core Concepts 7. Popping the Hood 8. Browser APIs 9. Working with Node.js 10. Accessing External Resources 11. Creating Clean and Maintainable Code 12. Using NextGeneration JavaScript 13. JavaScript Programming Paradigms 14. Understanding Functional Programming 15. Asynchronous Tasks Appendix

HTTP

http is the most important module of Node.js. It helps you to spin up a server that will listen to one specific port. It will let you transfer information over Hypertext Transfer Protocol (HTTP).

The createServer function takes one function as a parameter, which will be called when you make any request to the server. That function has two parameters: req and res. The first, the request parameter, is a stream that holds all the details of the request. For instance, if you are using a POST request to submit a form, then this object will hold all the values in it. The response parameter is also a stream, and you can use it to update the response header, status, and more:

res.writeHead(200, {'Content-Type': 'application/json'});

Here, you are updating one key in the header and writing the status code as 200, which is "OK." The difference between a parameter and a query is highlighted in the following figure:

Figure...

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 $19.99/month. Cancel anytime