req.acceptsCharsets()

req.acceptsCharsets(charset [, ...]) Returns the first accepted charset of the specified character sets, based on the request’s Accept-Charset HTTP header field. If none of the specified charsets is accepted, returns false. For more information, or if you have issues or concerns, see accepts.

req.accepts()

req.accepts(types) Checks if the specified content types are acceptable, based on the request’s Accept HTTP header field. The method returns the best match, or if none of the specified content types is acceptable, returns false (in which case, the application should respond with 406 "Not Acceptable"). The type value may be a single MIME type string (such as “application/json”), an extension name such as “json”, a comma-delimited list, or an array. For a list or array, the method returns the bes

Production Best Practices: Security

Overview The term “production” refers to the stage in the software lifecycle when an application or API is generally available to its end-users or consumers. In contrast, in the “development” stage, you’re still actively writing and testing code, and the application is not open to external access. The corresponding system environments are known as production and development environments, respectively. Development and production environments are usually set up differently and have vastly differe

Production best practices: performance and reliability

Overview This article discusses performance and reliability best practices for Express applications deployed to production. This topic clearly falls into the “devops” world, spanning both traditional development and operations. Accordingly, the information is divided into two parts: Things to do in your code (the dev part). Things to do in your environment / setup (the ops part). Things to do in your code Here are some things you can do in your code to improve your application’s performance

Process managers for Express apps

When you run Express apps for production, it is helpful to use a process manager to achieve the following tasks: Restart the app automatically if it crashes. Gain insights into runtime performance and resource consumption. Modify settings dynamically to improve performance. Control clustering. A process manager is somewhat like an application server: it’s a “container” for applications that facilitates deployment, provides high availability, and enables you to manage the application at runtim

Moving to Express 5

Overview Express 5.0 is still in the alpha release stage, but here is a preview of the changes that will be in the release and how to migrate your Express 4 app to Express 5. Express 5 is not very different from Express 4: The changes to the API are not as significant as from 3.0 to 4.0. Although the basic API remains the same, there are still breaking changes; in other words an existing Express 4 program might not work if you update it to use Express 5. To install the latest alpha and to previ

Moving to Express 4

Overview Express 4 is a breaking change from Express 3, so. That means an existing Express 3 app will not work if you update the Express version in its dependencies. This article covers: Changes in Express 4. An example of migrating an Express 3 app to Express 4. Upgrading to the Express 4 app generator. Changes in Express 4 There are several significant changes in Express 4: Changes to Express core and middleware system. The dependencies on Connect and built-in middleware were removed, so

Installing

Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory. $ mkdir myapp $ cd myapp Use the npm init command to create a package.json file for your application. For more information on how package.json works, see Specifics of npm’s package.json handling. $ npm init This command prompts you for a number of things, such as the name and version of your application. For now, you can simply hit RETURN to accept the defaults for mos

Hello world example

This is essentially going to be the simplest Express app you can create. It is a single file app — not what you’d get if you use the Express generator, which creates the scaffolding for a full app with numerous JavaScript files, Jade templates, and sub-directories for various purposes. First create a directory named myapp, change to it and run npm init. Then install express as a dependency, as per the installation guide. In the myapp directory, create a file named app.js and add the following

FAQ

How should I structure my application? There is no definitive answer to this question. The answer depends on the scale of your application and the team that is involved. To be as flexible as possible, Express makes no assumptions in terms of structure. Routes and other application-specific logic can live in as many files as you wish, in any directory structure you prefer. View the following examples for inspiration: Route listings Route map MVC style controllers Also, there are third-party ex