Node.js: Novice to Ninja
Copyright 2022 SitePoint Pty. Ltd.
Ebook ISBN: ISBN 978-1-925836-53-0
- Product Manager: Simon Mackie
- Technical Editor: Ivaylo Gerchev
- English Editor: Ralph Mason
- Cover Designer: Alex Walker
Notice of Rights
All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews.
Notice of Liability
The author and publisher have made every effort to ensure the accuracy of the information herein. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors and SitePoint Pty. Ltd., nor its dealers or distributors will be held liable for any damages to be caused either directly or indirectly by the instructions contained in this book, or by the software or hardware products described herein.
Trademark Notice
Rather than indicating every occurrence of a trademarked name as such, this book uses the names only in an editorial fashion and to the benefit of the trademark owner with no intention of infringement of the trademark.
![Published by SitePoint Pty Ltd 10-12 Gwynne St Cremorne VIC 3121 Australia - photo 2](/uploads/posts/book/307534/Images/sitepoint-logo-2012.png)
Published by SitePoint Pty. Ltd.
10-12 Gwynne St, Cremorne, VIC, 3121
Australia
Web: www.sitepoint.com
Email: books@sitepoint.com
About SitePoint
SitePoint specializes in publishing fun, practical, and easy-to-understand content for web professionals. Visit http://www.sitepoint.com/ to access our blogs, books, newsletters, articles, and community forums. Youll find a stack of information on JavaScript, PHP, design, and more.
About the Author
Craig is a UK-based freelance full-stack web developer, writer, and speaker whos passionate about standards and performance.
He began coding in the 1980s and started client-side JavaScript development on its release in 1995 when DHTML, spacer GIFs, and marquees were considered sophisticated. You may have encountered his work at SitePoint, where hes written more than 1,200 tutorials, and books including Jump Start Web Performance, Browser DevTool Secrets, and Docker for Web Developers.
Craig used Node.js from the start and hopes this book is a great first step on your server-side JavaScript journey. Contact him on Twitter @craigbuckler or at craigbuckler.com.
Preface
This book will help you get started with Node.js in the shortest possible time. Within a day or two you should have enough knowledge to write simple applications.
Prerequisites
This book is for web developers taking their first steps with Nodes.js. Ideally, you should understand web development concepts and technologies:
- web browsers (client-side HTML, CSS, and JavaScript)
- web servers (code to serve web pages and APIs)
It will help if you already know some JavaScriptperhaps from writing client-side scripts. This book explains some aspects of JavaScript in relation to Node.js, but you wont find deep dives into variables, loops, functions, objects, and so on.
A little knowledge of the command line, Git, and code editors such as VS Code will also be useful.
Conventions Used
Code Samples
Code in this book is displayed using a fixed-width font, like so:
A Perfect Summer's Day
It was a lovely day for a walk in the park.The birds were singing and the kids were all back at school.
Some lines of code should be entered on one line, but weve had to wrap them because of page constraints. An indicates a line break that exists for formatting purposes only, and should be ignored:
URL.open("https://www.sitepoint.com/responsive-web-design-real-user-testing/?responsive1");
Youll notice that weve used certain layout styles throughout this book to signify different types of information. Look out for the following items.
Tips, Notes, and Warnings
Hey, You!
Tips provide helpful little pointers.
Ahem, Excuse Me ...
Notes are useful asides that are relatedbut not criticalto the topic at hand. Think of them as extra tidbits of information.
Make Sure You Always ...
... pay attention to these important points.
Watch Out!
Warnings highlight any gotchas that are likely to trip you up along the way.
Where to Find Help
PHP and MySQL are moving targets, so chances are good that, by the time you read this, some minor detail or other of these technologies has changed from whats described in this book. Thankfully, SitePoint has a thriving community of PHP developers ready and waiting to help you out if you run into trouble, and we also maintain a list of known errata for this book you can consult for the latest updates.
The SitePoint Forums
The SitePoint Forums are discussion forums where you can ask questions about anything related to web development. You may, of course, answer questions, too. Thats how a discussion forum site workssome people ask, some people answer, and most people do a bit of both. Sharing your knowledge benefits others and strengthens the community. A lot of fun and experienced web designers and developers hang out there. Its a good way to learn new stuff, have questions answered in a hurry, and just have fun.
The SitePoint Forums include separate forums for PHP and MySQL:
The Code Archive
As you progress through this book, youll note a number of references to the code archive. This is a GitHub repository that contains each and every line of example source code thats printed in this book. If you want to cheat (or save yourself from carpal tunnel syndrome), go ahead and download the archive. Select the example from the dropdown that says Branch, then choose Clone or Download, and you can download a .zip
file for that example.
Alternatively, if youre familiar with Git, you can clone the repository.
Your Feedback
If youre unable to find an answer through the forums, or if you wish to contact us for any other reason, the best place to write is books@sitepoint.com
. We have a well-staffed email support system set up to track your inquiries, and if our support team members are unable to answer your question, theyll send it straight to us. Suggestions for improvements, as well as notices of any mistakes you may find, are especially welcome. You can also report and discuss issues in the books GitHub repository.
Lets Go
Now that Ive introduced myself, given you some broad tips, and shown you where to find help, its time to get started! Youll begin by setting up a development environment, and youll be writing your first lines of code very shortly.
Chapter 1: What is Node.js
Node.js is a JavaScript runtime, which means it runs programs written in JavaScript. Most developers use it to create command-line tools or web server applications.