preface

As we all know, in the beginning, the mainstream languages of back-end development were Java, PHP, and in recent years, Go, etc., while the emergence of Node.js enables javascript to run outside the browser, thus realizing the unification of the languages of the front and back ends.

Node.js is a JavaScript runtime environment based on Chrome V8 engine. Anyone who has JavaScript knowledge can learn to use Node for backend development.

Express is a streamlined and flexible Web application development framework based on the Node.js platform.

Install express

Before installing Express, first install the Node.js environment

Node.js installation description Address

After installing the node. js environment, run the NPM command to install the node. js tool

Use the command line tool

Create the project directory and enter

$ mkdir myExpress
$ cd myExpress
Copy the code

Initialize the project with NPM

$ npm init
Copy the code

Enter entry Point: Enter app.js or the name of the entry file you want

$ entry point: (index.js) app.js
Copy the code

Download and install Express

$ npm install express --save
Copy the code

Programming World universal slogan- Hello World!

Create an app.js file and enter the following content

const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World! ') }) app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) })Copy the code

Then directory execution will start a local port 3000 service, browser side access http://localhost:3000 can see Hello Word! the

$ node app.js

Example app listening at http://localhost:3000
Copy the code

Apply the generator tool express-Generator

Creating files, initializations, and writing app.js is not too much hassle. Is there a way to create a complete project architecture with express configuration in one click? Express-generator

Global installation

npm install -g express-generator
Copy the code

After successful installation, use the command “Express project name” for example

express app
cd app
npm i
npm run start
Copy the code

To see Welcome to Express, go to http://localhost:3000 in your browser

Express Directory Analysis

├ ─ ─ app. Js/application/master file ├ ─ ─ bin / / the default directory server script │ └ ─ ─ the WWW / / server default script ├ ─ ─ node_modules / / dependent package │ └ ─ ─... Javascripts │ ├── images // Image Resources │ ├── javascripts │ ├── index.js │ ├── index.js │ ├── index.js │ ├── index.js │ ├── index.js │ ├── index.js │ ├── index.js │ ├── index.js │ ├── index.js │ ├── index.js ├── index. Jade // home page ├─ layout.jade // public pageCopy the code

The above is all the content of the first knowledge, thank you very much for seeing here, if this article is good or a little help to you, ask for like, attention, share, of course, any questions can be discussed in the comments, I will actively answer, thanks again