1. Install Express1.1 installation Express frame
First make sure that node. js is installed, and then go to the terminal to install the Express framework using administrator status.
# 安装 express$ sudo npm install -g express
1.2 Installing the Express command-line tool
After installation, if you are using Express version 4.0, there is a need to be aware that the 4.x version of Express has separated the command line tool Express-generator.
We now have a global installation that only needs to install this command-line tool, as instructed below.
# 安装 express-generator$ sudo npm install -g express-generator
2. Create application 2.1 use Express to create an application
After installing the Express command line tool above, go to the directory where you want to create the app, and then create a App_demo app with the following command
# 创建基于 ejs 的应用$ express --view=ejs App_Demo
After the app is created, the terminal will prompt the following
create : App_Demo/create : App_Demo/public/create : App_Demo/public/javascripts/create : App_Demo/public/images/create : App_Demo/public/stylesheets/create : App_Demo/public/stylesheets/style.csscreate : App_Demo/routes/create : App_Demo/routes/index.jscreate : App_Demo/routes/users.jscreate : App_Demo/views/create : App_Demo/views/error.ejscreate : App_Demo/views/index.ejscreate : App_Demo/app.jscreate : App_Demo/package.jsoncreate : App_Demo/bin/create : App_Demo/bin/wwwchange directory: $ cd App_Demoinstall dependencies: $ npm installrun the app: $ DEBUG=app-demo:* npm start
2.2 Installation Dependencies
Depending on the last step after you create the app, follow the final prompts to install the dependency by following the command.
# 切换目录并安装依赖包$ cd App_Demo && npm install
2.3 Starting the Service
When the above dependencies are installed correctly, enter the following command to start the service.
# 启动服务,运行 Node.js 程序$ npm start# 或# 启动服务,运行 Node.js 程序$ node ./bin/www
Attention
- If you have introduced a database module in your project and connected to a database, start the database before the next time you start it, or you may be able to report errors that the database module could not find to start up.
2.4 Authentication Service
- Then open the browser and visit http://localhost:3000 if the Welcome to express description Express has successfully installed and created the App_demo app.
Instructions to create an Express node. JS Project