Express is a fast, open and minimalist Web development framework based on the Node.js platform.

Web applications

Express is a minimum-sized flexible Node.js Web application development framework that provides a powerful set of capabilities for Web and mobile applications.

performance

Express provides streamlined Web-based application functionality.

Development environment mongoDB, NodeJS

One, installation and simple creation project

(Basic learning, building specific projects skip this step, go straight to 2, building)

1. Installation Node. Js

2. Create projects

Create a directory, then enter it and use it as the current working directory

$ mkdir blog-server
$ cd blog-server
Copy the code

Create a package.json file for your application using the NPM init command.

$ npm init
Copy the code

This command will ask you to enter several parameters, and press Enter to select default:

3. Install the Express

Next, install Express in the blog-server directory and save it in the dependency list

$ npm install express --save
Copy the code

4. Create an import file

Create a file named index.js in the project directory

const express = require("express");
const app = express();

app.get('/', (req, res) => res.send('Hello World! '))

app.listen(3000, () = >console.log('Example app listening on port 3000! '))
Copy the code

Then execute the command:

$ node index.js
Copy the code

You can see the output

Example app listening on port 3000!
Copy the code

This creates a very simple Express project

2. Build (skip step 1)

Express application generator

1. The structures,

You can quickly create an application skeleton by applying the generator tool Express-Generator

Express-generator includes the Express command line utility. Run the following command to install it:

express --view=pug blog-server
Copy the code

Install all dependencies:

$ cd blog-server
$ npm install
Copy the code

2. Start

npm start
Copy the code

Then in your browser, go to http://localhost:3000/ and you can see the application

A typical application created with a generator has the following structure:

├ ─ ─ app. Js ├ ─ ─ bin │ └ ─ ─ WWW ├ ─ ─ package. The json ├ ─ ─ public │ ├ ─ ─ images │ ├ ─ ─ javascripts │ └ ─ ─ stylesheets │ └ ─ ─ Style. The CSS ├ ─ ─ routes │ ├ ─ ─ index. The js │ └ ─ ─ the users. The js └ ─ ─ views ├ ─ ─ the error. The relation ├ ─ ─ index. The relation └ ─ ─ layout. 7 relation directories, 9 filesCopy the code