Jörg Krause
Jörg Krause
Berlin, Germany
Any source code or other supplementary materials referenced by the author in this text are available to readers at www.apress.com . For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/ . Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter.
ISBN 978-1-4842-2510-3
e-ISBN 978-1-4842-2511-0
DOI 10.1007/978-1-4842-2511-0
Library of Congress Control Number: 2016961762
© Jörg Krause 2017
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Printed on acid-free paper
Node.js is one of the most fascinating software environments of recent years. Today it’s in version v6.x, a quite mature version. There are two lines: one with Long Term Support (LTS) currently in version 4.x, and the one with the most recent features in version 6.x. The version 6.x has updates quite often, sometimes weekly.
It’s necessary to have a well-known language to create web applications instead of inventing just another language all the time. Think of the history of Perl, PHP, Java, Ruby, C in all it derivates, and many more. The final answer might be JavaScript.
The foundation of JavaScript on the server is the V8 engine from Chrome browser that has been extracted and made available as an executable. And it is available on all platforms, finally.
For developers with a strong background in traditional object-oriented languages such as C# or Java, it might sound odd that JavaScript has such a tremendous impact and success. It’s a weird mixture of a very simple language and a very rich and quickly expanding ecosystem.
All codes from the book are available on Github for easy testing and download.
The book is very focused on the first steps and easy examples. There is almost no advanced code and the reference parts contain only those functions required to execute a web application. The purpose is to have all this information handy in one place instead of flipping through hundreds of online sources.
The combination of Node, Express, and Pug is well-tested and the versions used here work together smoothly. There s no support for other software modules and other version combinations.
This book is aimed at beginners and web developers who are new to the web world. Node serves mainly the back-end developer. Maybe you are also a web designer, who discovered Node as an excellent way to upgrade your web pages with dynamic elements.
In any case, I tried not to ask any prerequisites or conditions of the reader. You do not need to be a computer scientist, nor in perfect command of language. You don’t need to know rocket science. No matter what context you have encountered on Jade, you will be able to read this text.
In order to understand all examples, you need a working environment for creating web pages. That can be a Windows, a Linux, or even a Mac. It’s possible to use any text editor to get the stuff running, but I recommend you use one with a little support while typing the stuff. Check editors such as Visual Studio Code or Sublime Text.
If you have accidentally found this text and cannot do anything with the term “Bootstrap,” read it anyway. You will be learning one of the most modern techniques of web development, and the future belongs to the circle of excellent developers who can be build good-looking and device-independent sites.
You can find the sample project to this book on Github:
I will not dictate how you should read this text. In the first draft of the structure, I have tried several variations and found that there exists no ideal form. However, readers tend today to consume smaller chunks, independent chapters, and focused content. This book addresses this trend by reducing content to small, focused chunks, with no extraneous material.
Beginners should read the text as a narrative from the first to the last page. Those who are already somewhat familiar can safely skip certain sections.
The theme is not technically easy to master, because scripts are often too extensive and it would be nice if you could support the best optical reading form. I have therefore included extra line breaks used to aid readability.
In general, each program code is set to a non-proportional font. In addition, scripts have line numbers:
1 function send(){
2 // do some stuff here
3 }
If you find you need to enter something in the prompt or in a dialog box, this part of the statement is in bold:
The first character is the prompt and is not entered. I use the Linux prompt and the bash shell in the book. The commands will work, without any exception, unchanged even on Windows. The only difference then is the command prompt C:> or something similar at the beginning of the line. Usually the instructions are related to relative paths or no paths at all, so the actual prompt shouldn’t matter despite the fact that you will be in your working folder.
Expressions and command lines are sometimes peppered with all types of characters, and in almost all cases, it depends on each character. Often, I’ll discuss the use of certain characters in precisely such an expression, then the “important” characters with line breaks alone, and also—in this case—line numbers. Line numbers are used to reference the affected symbol in the text exactly (note the : character in line 2):
1 a.test {
2 :hover {
3 color: red
4 }
5 }
The font is non-proportional, so that the characters are countable and opening and closing parentheses are always among themselves.
To facilitate the orientation in the search for a solution, there is a whole range of symbols that are used in the text.
This is a tip.
This is an information.
This is a warning.
There are no questionnaires, exercises, or self-tests. It’s just a reference, an easy-to-read text to get you on your way.
Node.js is a programming environment based on JavaScript. It’s mainly used for web application development, but not restricted to same. In conjunction with the Node Package Manager (npm), it provides a powerful environment to create platform-independent applications.
This book shows the basic parts you need to create a web application. Apart from Node itself, this includes the middleware framework Express and the template language Pug (formerly known as JADE).
The content presents Node in its elementary form, shows the programming of a simple web application, and explains the major modules. In the same style, Express and Pug are explained. The client does not have any particular role in this book. The pages served by the examples are plain HTML.
Jörg Krause has been working with software and software technology since the early 1980’s, beginning with a ZX 81 and taking his first steps as a programmer in BASIC and assembly language. He studied Information Technology at Humboldt University, Berlin but left early, in the 90’s, to start his own company. He has worked with Internet Technology and software development since the early days when CompuServe and FidoNet dominated. He’s been with Microsoft technologies and software since Windows 95.
In 1998, he worked on one of the first commercial e-commerce solutions, and wrote his first book in Germany, E-Commerce and Online Marketing , published by Carl Hanser Verlag, Munich. Due to its wide success, he started working as a freelance consultant and author in order to share his experience and knowledge with others. He has written several books for Apress, Hanser, Addison Wesley and other major publishers along with several self-published books—a total of over sixty titles. He also publishes articles in magazines and speaks at major conferences in Germany. Currently, Jörg works as an independent consultant, software developer, and author in Berlin, Germany.
In his occasional spare time, Jörg enjoys reading thrillers and science fiction novels, and going on a round of golf.
3.144.97.216