|
- Express examples
Explore a collection of Express js application examples covering various use cases, integrations, and advanced configurations to help you learn and build your projects
- Hello world example - Express
Hello world example Embedded below is essentially 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
- Express basic routing
This tutorial assumes that an instance of express named app is created and the server is running If you are not familiar with creating an app and starting it, see the Hello world example The following examples illustrate defining simple routes Respond with Hello World! on the homepage:
- Using template engines with Express
After the view engine is set, you don’t have to specify the engine or load the template engine module in your app; Express loads the module internally, for example:
- Serving static files in Express
The root argument specifies the root directory from which to serve static assets For more information on the options argument, see express static For example, use the following code to serve images, CSS files, and JavaScript files in a directory named public:
- Express vhost middleware
var connect = require('connect') var serveStatic = require('serve-static') var vhost = require('vhost') var mailapp = connect() add middlewares to mailapp for mail example com create app to serve static files on subdomain var staticapp = connect() staticapp use(serveStatic('public')) create main app var app = connect() add vhost
- Express body-parser middleware
This example demonstrates adding a generic JSON and URL-encoded parser as a top-level middleware, which will parse the bodies of all incoming requests This is the simplest setup
|
|
|