Home  >  Article  >  Development Tools  >  How to build a local server with vscode

How to build a local server with vscode

王林
王林Original
2020-01-09 14:47:123725browse

How to build a local server with vscode

1. Install Node

2. Install express

Open the terminal and enter the following code :

// 全局安装
npm install express -g

// 测试是否安装成功
express -h

// 安装如果出现问题,则运行
npm install express-generator -g

3. Create the project folder

(1) Steps:

1.express myapp

How to build a local server with vscode

2. cd myapp

3. npm install

Instructions for the above steps: First create the project folder myapp, enter the folder, and initialize the project.

(2) Express framework composition

How to build a local server with vscode

Description:

bin is the startup file of the project, configure how to start the project, the default npm start, where the www file is used to start the service

node_modules is the module required by the file.

public is the static file of the project, where js, css, img and other files are placed.

routes is the routing information file of the project, which controls address routing.

views are view files, which place template files such as ejs or jade (actually equivalent to files in html form)

The above is the MVC framework model based on express, which is the basic composition of a Web project .

4. Run

Enter the terminal in vsCode: node ./bin/www to start the service.

Note: The path of node ./bin/www` can be found in the package.json file. It will be different when you install it yourself.

Access in the browserlocalhost:3000The effect shown in the figure below indicates that the startup is successful:

Note: The 3000 port number is in the bin file In the www file under

How to build a local server with vscode

, related articles and tutorials are recommended: vscode tutorial

The above is the detailed content of How to build a local server with vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn