Nodejs uses express to create a simple web application, nodejsexpress
When initializing a project, Express needs to specify the template engine. By default, Jade and ejs are supported.
Here we use the ejs template engine: (for introduction to ejs, You can first get a rough idea from the encyclopedia)
EJS is a Javascript template library used to generate HTML strings from JSON data.
When using express to create a website, use the ejs template engine to create a basic website structure. The following is used in the current directory: the express-t ejs sophiehui command creates a subdirectory of sophiehui in the current directory, as shown in the following figure:
The last line prompts us to install the dependency, so next we will go to the sophiehui directory to install the dependency: npm install (The npm install function without parameters is to check the package. json file in the current directory and automatically install all specified dependencies.)
Wait until the execution ends.
View your first express application: npm start (use node app in the Command Prompt window. js), and then access http: // localhost: 3000/to see the effect of 2.