If you’re a software developer with a few years of experience, and you’re new to Node.js or web development, join popular instructor Benjamin Lin and author and founder of Node University Azat Mardan for Introduction to Node.js, now available on edX. In just a few hours (and using the latest materials), make the leap from desktop apps, and see how easy and fast it is to get started on Node.js. Plus, who better to learn from than the always-entertaining Benjamin and his colleague Azat, who has written more than a dozen books on Node.js?
In the previous post, we learned how to perform HTTP/2 server push in a Node server. We also covered the benefits of server push there so to avoid duplication we won’t list them here. We used
spdy for server push and H2. But most of the times Node developers don’t work with core HTTP server, they use a framework like Express. So let’s see how we can implement server push in Express.
HTTP/2 is the new standard of the web. It has many great features which will make the web faster and simplify the development. For example, no need to concatenate files thanks to multiplexing, or a server push which can send files before a browser knows it need them.
This post won’t cover all advantages of HTTP/2. You can read about them online. No need to go into all the details and duplicate text here. Instead, we’ll focus on server push and implement it in Node.js using Express and the
HTTP2 is the first major upgrade to the good old HTTP protocol in over 15 years (first HTTP is circa 1991)! It is optimized for modern websites. The performance is better without complicated hacks like domain sharding (having multiple domains) or file concatenation (having one large file instead of many small ones).
Have you ever wanted to learn basics of Node.js and the most popular Node.js web framework Express.js? If you are experienced web developer or software engineer who wants to learn Node.js and build some servers along the way, then this self-study workshop is for you.
What is ExpressWorks? It’s an automated tool which allows to learn Express.js from the author of one of the best books on Express.js—Pro Express.js— with this workshop that will teach you basics of Express.js and building Node.js web apps (a.k.a. servers).
You will walk through adventures via command-line interface. Each adventure has a problem, hints, and the solutions.
Some of the resources before you get started:
- ExpressWorks Docs: https://github.com/azat-co/expressworks.
- FREE Express.js cheatsheet—>>>: https://gum.co/NQiQ/git-874E6FB4
- Pro Express.js book: http://proexpressjs.com.
The entire playlist: on YouTube or just watch individual solutions below. Try solving problems without looking at the solutions!
I hated Jade as many other Node.js developes do. But I changed 180 after I realized that it has tons of features.
At Storify and DocuSign we used Jade for EVERYTHING. We used Jade even in the browser. There is a little trick called jade-browser. It was developed by folks at Storify. I maintained it for a bit.
The funny thing is that DocuSign team used jade-browser long before they met me. They swear they hired me without knowing that I was involved in that library. :-)
- Jade and Handlebars usage in Express.js 4
- Project: adding Jade templates to Blog
Last week, I did a live Q&A session for people who bought my new book Pro Express.js, but you can watch the recording here. Click on the apps icon (next to the ? icon), and then click on the Q&A button to see the questions. If you haven’t bought Pro Express.js, then you can do it on Amazon.com… and start mastering the framework for you Node.js web development.
PS: You can also watch the session on YouTube, but I recommend Google +.
Here is the summary of questions and answers which you can also get in a PDF —>>> Pro Express.js Q&A, or read below.
The long-anticipated Express.js manual is ready and was sent to to print at this week (December 24, 2014). To summarize the book, Pro Express.js: Master Express.js—The Node.js Framework For Your Web Development is all about understanding Express.js and building web apps with this framework and its middleware. Spend two minutes to read this post, to know how you can benefit from this valuable resource and the release.
Becoming a Better Node.js Developer
If you an intermediate or advanced beginner Node.js developer and want to become better at this cool, new technology, then you have lots of questions about the best practices and patterns. Most likely you’ve encountered Express.js, and you wish you knew more about useful settings and options to configure Express.js and its middleware.
The reason why I know these things is that, before I became proficient with Node.js and Express.js, I was a beginner just like you. Also, I’ve been in a position when I needed to learn Express.js quickly. In those sad moments, I was flat out miserable and often had to read the source code for the lack of a good documentation and examples. I wish I had Pro Express.js with me back then to explain the mechanisms in plain English, and provide inspiring code patterns that I could re-use in my projects. That’s why I’m confident that Pro Express.js will be great for intermediate Node.js developers (and advanced-beginners).
Pro Express.js can solve your pains and problems by providing the following benefits:
TL;DR: This post is about URL parameters and routing in Express.js, and it’s an excerpt (Chapter 6) from my new book Pro Express.js: Master Express.js—The Node.js Framework For Your Web Development. The book was released this week (~December 24, 2014), but we have a great limited-time offer for you which will be announced on Sunday, December 28, 2014 on Webapplog.com. This post is the last post in the series of excerpts from Pro Express.js with other posts as follow: Error Handling and Running an Express.js App, Express.js Security Tips, LoopBack 101: Express.js on Steroids, Sails.js 101 and Secret Express.js Settings.
To review, the typical structure of an Express.js app fig(which is usually a
app.js file) roughly consists of these parts, in the order shown:
Dependencies : A set of statements to import dependencies
Instantiations : A set of statements to create objects
Configurations : A set of statements to configure system and custom settings
Middleware : A set of statements that is executed for every incoming request
Routes : A set of statements that defines server routes, endpoints, and pages
Bootup : A set of statements that starts the server and makes it listen on a specific port for incoming requests
This chapter covers the fifth category, routes and the URL parameters that we define in routes. These parameters, along with the app.param() middleware, are essential because they allow the application to access information passed from the client in the URLs (e.g.,
books/proexpressjs). This is the most common convention for REST APIs. For example, the
http://hackhall.com/api/posts/521eb002d00c970200000003 route will use the value of
521eb002d00c970200000003 as the post ID.
Parameters are values passed in a query string of a URL of the request. If we didn’t have Express.js or a similar library, and had to use just the core Node.js modules, we’d have to extract parameters from an
HTTP.request object via some
require('url').parse(url, true) function “trickery.”
Let’s look closer at how to define a certain rule or logic for a particular URL parameter.
TL;DR: This text is an excerpt (Chapter 9) from Pro Express.js: Master Express.js—The Node.js Framework For Your Web Development. The book will be released next week (December 24, 2014), and we’ll announce a great limited-time offer on it on Sunday, December 28, 2014. So stay tuned… and happy Holidays!!!
Good web applications must have informative error messages to notify clients exactly why their request has failed. Errors might be caused either by the client (e.g., wrong input data) or by the server (e.g., a bug in the code).
The client might be a browser, in which case the application should display an HTML page. For example, a 404 page should display when the requested resource is not found. Or the client might be another application consuming our resources via the REST API. In this case, the application should send the appropriate HTTP status code and the message in the JSON format (or XML or another format that is supported). For these reasons, it’s always the best practice to customize error-handling code when developing a serious application.
In a typical Express.js application, error handlers follow the routes. Error handling deserves its own section of the book because it’s different from other middleware. After the error handlers, we’ll cover the Express.js application methods and ways to start the Express.js app. Therefore, the major topics of this chapter are as follows:
- Error handling
- Running an app