Express-Web application Development framework based on node. JS Platform

Source: Internet
Author: User

Web Apps
Express is a minimalist, flexible Web application Development framework based on the node. JS platform that provides a range of powerful features to help you create a wide variety of web and mobile device applications.
Api
Rich HTTP shortcuts and any combination of Connect middleware make it fast and easy to create robust, friendly APIs.
Performance
Express does not abstract the existing features of node. JS two times, we just extend the basic functionality required for WEB applications on top of it.
LoopBack offers sponsorship
Develop Model-driven Apps with an express-based framework.
Find out more at Loopback.io.
Express App Builder
The App Builder Tool Express lets you quickly create an app's skeleton.

Install with the following command:

$ NPM Install Express-generator-g
The-H option lists all available command-line options:

$ express-h

usage:express [Options] [dir]

Options:

-h, --help          output usage information-V, --version       output the version number-e, --ejs           add ejs engine support (defaults to jade)    --hbs           add handlebars engine support-H, --hogan         add hogan.js engine support-c, --css <engine>  add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)    --git           add .gitignore-f, --force         force on non-empty directory

For example, the following example creates an app named MyApp under the current working directory.

$ Express MyApp

Create:myapp
Create:myapp/package.json
Create:myapp/app.js
Create:myapp/public
Create:myapp/public/javascripts
Create:myapp/public/images
Create:myapp/routes
Create:myapp/routes/index.js
Create:myapp/routes/users.js
Create:myapp/public/stylesheets
Create:myapp/public/stylesheets/style.css
Create:myapp/views
Create:myapp/views/index.jade
Create:myapp/views/layout.jade
Create:myapp/views/error.jade
Create:myapp/bin
Create:myapp/bin/www
Then install all dependent packages:

$ cd MyApp
$ NPM Install
Launch this app (MacOS or Linux platform):

$ Debug=myapp NPM Start
The Windows platform uses the following commands:

Set Debug=myapp & NPM start
Then open the Http://localhost:3000/URL in the browser to see the app. I

Applications created with the Express app builder typically have the following directory structure:

.
├──app.js
├──bin
│└──www
├──package.json
├──public
│├──images
│├──javascripts
│└──stylesheets
│└──style.css
├──routes
│├──index.js
│└──users.js
└──views
├──error.jade
├──index.jade
└──layout.jade

7 Directories, 9 files
Creating an app with Express app growth is just one of many approaches. You can not use it, you can also modify it to meet your needs, are open source!

Using the template engine in Express
You need to set the following settings in your app to let Express render template files:

Views, put the directory of template files, such as: app.set (' views ', './views ')
View engine, template engine, for example: App.set (' View engine ', ' Jade ')
Then install the appropriate template engine NPM package.

$ NPM Install Jade--save
The Express-compatible template engine, such as Jade, uses Res.render () to invoke its export method __express (FilePath, Options, callback) render template.

There are some template engines that do not follow this convention, and Consolidate.js can map all the popular template engines in Node to this Convention so that it can seamlessly connect with Express.

Once the view engine is set up, you do not need to explicitly specify the engine or load the template engine module in the app, and Express is already loaded internally, as shown below.

App.set (' View engine ', ' Jade ');
Under the Views directory, generate a jade template file named Index.jade, which reads as follows:

Html
Head
title!= Title
Body
H1!= message
Then create a route rendering Index.jade file. If you do not set view engine, you need to indicate the suffix of the view file, or you will miss it.

App.get ('/', function (req, res) {
Res.render (' index ', {title: ' Hey ', message: ' Hello there! '});
});
When you send a request to the home page, "Index.jade" is rendered as HTML.

Read "Developing a template engine for express" to see how the template engine works in Express.

Express-Web application Development framework based on node. JS Platform

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.