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
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
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:3000
The 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
, 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!