Pro Express.js (eBook)
XXII, 372 Seiten
Apress (Verlag)
978-1-4842-0037-7 (ISBN)
In order to get the best from this book, you will be familiar with Node.js scripts and able to install packages using npm. In the deep API reference, each aspect of the Express.js API is explained clearly with a simple exercise to demonstrate its usage. This includes configuration, settings and environments; different middleware and its uses; templating engines; extracting parameters and routing; request and response; error handling; and running an app. In the next part you'll delve into abstraction, streams, authentication, multithreading, Socket.io, security, and more complex modules. You will also learn about smaller frameworks built using Express.js, such as Sails.js, and Derby. Finally you'll build real-world apps including a REST API, Todo App, and Instagram gallery.
Express.js is used by a range of well-known companies such as MySpace and Storify, and it's becoming more and more likely that it'll be a required skill for new developers. With this book you can skip learning via complicated documentation, and get the information from a developer who's been using Express.js for long enough to explain things well. Add Pro Express.js to your library today.
Azat Mardan has over 12 years of experience in web, mobile and software development. With a Bachelor's Degree in Informatics and a Master of Science in Information Systems Technology degree, Azat possesses deep academic knowledge as well as extensive practical experience.Currently Azat works as an engineer at the curated social media news aggregator website Storify.com. He teaches technical classes at General Assembly San Francisco and Hack Reactor to much acclaim. In his spare time, Azat writes about technology on his blog webAppLog.com. He is also an author of artisanal book Rapid Prototyping with JS: Agile JavaScript Development.Previously, Azat has worked as a CTO/co-founder at Gizmo, an enterprise cloud platform for mobile marketing campaigns, and has undertaken the prestigious 500 Startups business accelerator program. Prior to this, Azat was developing mission-critical applications for government agencies in Washington, DC, including the National Institutes of Health, the National Center for Biotechnology Information, and the Federal Deposit Insurance Corporation, as well as Lockheed Martin.Azat is a frequent attendee at Bay Area tech meet-ups and hackathons (StartupBus 2013, AngelHack hackathon 12 finalist with team FashionMetric.com).
Pro Express.js is for the reader who wants to quickly get up-to-speed with Express.js, the flexible Node.js framework. Author Azat Mardan clearly explains how to start developing with Express.js with a basic 'Hello World', and then delves into a deep API reference, before looking at common and abstract development problems. Lastly, you will learn how to build a series of real-world apps in order to cement your knowledge.In order to get the best from this book, you will be familiar with Node.js scripts and able to install packages using npm. In the deep API reference, each aspect of the Express.js API is explained clearly with a simple exercise to demonstrate its usage. This includes configuration, settings and environments; different middleware and its uses; templating engines; extracting parameters and routing; request and response; error handling; and running an app. In the next part you'll delve into abstraction, streams, authentication, multithreading, Socket.io, security, and more complex modules. You will also learn about smaller frameworks built using Express.js, such as Sails.js, and Derby. Finally you'll build real-world apps including a REST API, Todo App, and Instagram gallery. Express.js is used by a range of well-known companies such as MySpace and Storify, and it's becoming more and more likely that it'll be a required skill for new developers. With this book you can skip learning via complicated documentation, and get the information from a developer who's been using Express.js for long enough to explain things well. Add Pro Express.js to your library today.
Azat Mardan has over 12 years of experience in web, mobile and software development. With a Bachelor's Degree in Informatics and a Master of Science in Information Systems Technology degree, Azat possesses deep academic knowledge as well as extensive practical experience.Currently Azat works as an engineer at the curated social media news aggregator website Storify.com. He teaches technical classes at General Assembly San Francisco and Hack Reactor to much acclaim. In his spare time, Azat writes about technology on his blog webAppLog.com. He is also an author of artisanal book Rapid Prototyping with JS: Agile JavaScript Development.Previously, Azat has worked as a CTO/co-founder at Gizmo, an enterprise cloud platform for mobile marketing campaigns, and has undertaken the prestigious 500 Startups business accelerator program. Prior to this, Azat was developing mission-critical applications for government agencies in Washington, DC, including the National Institutes of Health, the National Center for Biotechnology Information, and the Federal Deposit Insurance Corporation, as well as Lockheed Martin.Azat is a frequent attendee at Bay Area tech meet-ups and hackathons (StartupBus 2013, AngelHack hackathon 12 finalist with team FashionMetric.com).
Contents at a Glance 3
Contents 338
About the Author 348
About the Technical Reviewers 349
Foreword 350
Acknowledgments 352
Introduction 5
Part i: Getting Started 8
Chapter 1: Starting with Express.js 9
How Express.js Works 10
Third-Party Dependencies 11
Instantiations 11
Connecting to Databases 11
Configuring Express.js App Settings 12
Defining Middleware 12
Defining Routes 12
Starting the App 12
Express.js Installation 13
Express.js Generator In stallation 18
Summary 20
Chapter 2: Hello World Example 21
Getting Started 21
Using Request Handlers 23
Outputting Terminal Messages 23
Enhancing the App 25
Generator Commands 26
Generating a Skeleton Express.js app 27
Reviewing the Application’s Structure 28
App.js 29
MVC Structure and Modules 34
Watching for File Changes 35
Summary 36
Part II: Deep API Reference 37
Chapter 3: Configuration, Settings, and Environments 38
Configuration 38
app.set(?) and app.get(?) 39
app.enable(?) and app.disable(?) 39
app.enabled(?) and app.disabled(?) 40
Settings 40
env 41
view cache 41
view engine 41
views 43
trust proxy 43
jsonp callback name 43
json replacer and json spaces 45
case sensitive routing 46
strict routing 47
x-powered-by 47
etag 49
query parser 50
subdomain offset 50
Environments 50
Summary 54
Chapter 4: Working with Middleware 55
Applying Middleware 56
Essential Middleware 59
compression 60
morgan 62
body-parser 63
urlencoded() 64
cookie-parser 65
express-session 66
csurf 66
express.static() 68
connect-timeout 68
errorhandler 70
method-override 70
response-time 71
serve-favicon 72
serve-index 73
vhost 75
connect-busboy 76
Other Middleware 77
Summary 77
Chapter 5: Template Engines and Consolidate.js 78
How to Use Template Engines 79
app.engine() 80
Uncommon Libraries 81
Template Engine Choices 85
Jade 85
Haml.js 85
EJS 85
Handlebars.js 85
Hogan.js Adapters 86
Combyne.js 86
Swig 86
Whiskers 86
Blade 86
Haml-Coffee 86
Webfiller 86
Consolidate.js 86
Summary 88
Chapter 6: Parameters and Routing 89
Parameters 89
app.param() 93
Routing 96
app.VERB() 97
app.all() 100
Trailing Slashes 100
Router Class 100
router.route(path) 101
Request Handlers 102
Summary 104
Chapter 7: Express.js Request Object 105
request.query 106
request.params 108
request.body 110
request.route 112
request.cookies 113
request.signedCookies 115
request.header(?) and request.get(?) 115
Other Attributes and Methods 115
Summary 119
Chapter 8: Express.js Response Object 120
response.render(?) 120
response. locals 123
response.set(?) 125
response.status(?) 127
response.send(?) 128
response.json(?) 131
response.jsonp(?) 133
response.redirect(?) 134
Other Response Methods and Properties 134
Streams 138
Summary 140
Chapter 9: Error Handling and Running an App 141
Error Handling 141
Running an App 145
app.locals 145
app.render() 145
app.mountpath 146
app.on(‘mount’, function(parent){...}) 147
app.path() 147
app.listen() 147
Summary 151
Part III: Solving Common and Abstract Problems 152
Chapter 10: Abstraction 153
Middleware 153
Routes 154
Combining Middleware and Routes 156
Summary 158
Chapter 11: Database, Keys and Stream Tips 159
Using Databases in Modules 159
Keys and Passwords 161
JSON File 162
Environment Variables 163
Streams 163
Summary 168
Chapter 12: Redis and Authentication Patterns 169
Redis 169
Authentication Patterns 173
Summary 174
Chapter 13: Multithreading with Clusters 175
A Multithreading Example 175
Summary 178
Chapter 14: Applying Stylus, Less, and Sass 179
Stylus 179
Less 180
Sass 181
Summary 181
Chapter 15: Security Tips 182
Cross-Site Request Forgery 182
Process Permissions 185
HTTP Security Headers 185
Input Validation 187
Summary 189
Chapter 16: Socket.IO and Express.js 190
Using Socket.IO 190
Running the App 194
Summary 195
Chapter 17: Domain and Express. js 196
Defining the Problem 196
Exploring a Basic Domain Example 197
Writing a Domain App 197
Summary 201
Chapter 18: Sails.js, DerbyJS, LoopBack, and Other Frameworks 202
Sails.js 202
DerbyJS 204
LoopBack 207
Other Frameworks 210
Summary 211
Part IV: Tutorials and Examples 212
Chapter 19: Instagram Gallery 213
Starting the Instagram Gallery 213
Viewing the Gallery 217
Summary 218
Chapter 20: Todo App 219
Overview 220
Setup 225
App.js 227
Routes 233
Jade 237
Less 243
Summary 244
Chapter 21: REST API 245
RESTful API Basics 246
Test Coverage 247
Dependencies 252
Server Implementation 253
Summary 257
Chapter 22: HackHall 258
What Is HackHall? 258
Running HackHall 259
Structure 266
Package. json 267
Express.js App 268
Routes 273
index. js 273
auth. js 273
main. js 278
users. js 281
application. js 287
posts. js 290
Mongoose Models 297
Mocha Tests 305
Summary 310
Appendix A: Related Reading and Resources 311
Other Node.js Frameworks 311
Node.js Books 313
JavaScript Classics 314
Courses 314
Appendix B: Migrating Express.js 3.x to 4.x: Middleware, Route, and Other Changes 315
Introducing Unbundled Middleware in Express.js 4 315
Removing Deprecated Methods from Express.js 4 Apps 317
app.configure() 317
app.router 317
res.on(‘header’) 318
res.charset 318
res.headerSent 318
req.accepted() 318
Other Express.js 4 Changes 318
app.use() 318
res.location() 318
app.route() 318
json spaces 319
req.params 319
res.locals 319
req.is 319
Express.js Command-Line Generator 319
Exploring the New Express.js 4 Route Instance and How to Chain It 319
Further Express.js 4 Migration Reading Links 321
Appendix C: Express.js 4 Cheat Sheet 322
Installation 323
Generator 323
Basics 323
HTTP Verbs and Routes 324
Request 324
Request Header Shortcuts 324
Response 325
Handlers Signatures 325
Stylus and Jade 325
Body 325
Static 326
Connect Middleware 326
Other Popular Middleware 326
Appendix D: ExpressWorks 327
Installation 327
Usage 328
Resetting 328
Tasks 328
Hello World 328
Jade 328
Good Old Form 329
Static 329
Stylish CSS 329
Param Pam Pam 329
What’s in a Query 330
JSON Me 330
Summary 330
Index 331
| Erscheint lt. Verlag | 26.12.2014 |
|---|---|
| Zusatzinfo | XXII, 372 p. 93 illus. |
| Verlagsort | Berkeley |
| Sprache | englisch |
| Themenwelt | Mathematik / Informatik ► Informatik ► Theorie / Studium |
| Mathematik / Informatik ► Informatik ► Web / Internet | |
| ISBN-10 | 1-4842-0037-3 / 1484200373 |
| ISBN-13 | 978-1-4842-0037-7 / 9781484200377 |
| Informationen gemäß Produktsicherheitsverordnung (GPSR) | |
| Haben Sie eine Frage zum Produkt? |
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich