- ExpressJS 教程
- ExpressJS - 首页
- ExpressJS - 概述
- ExpressJS - 环境
- ExpressJS - Hello World
- ExpressJS - 路由
- ExpressJS - HTTP 方法
- ExpressJS - URL 构建
- ExpressJS - 中间件
- ExpressJS - 模板引擎
- ExpressJS - 静态文件
- ExpressJS - 表单数据
- ExpressJS - 数据库
- ExpressJS - Cookie
- ExpressJS - Session
- ExpressJS - 身份验证
- ExpressJS - RESTful API
- ExpressJS - 脚手架
- ExpressJS - 错误处理
- ExpressJS - 调试
- ExpressJS - 最佳实践
- ExpressJS - 资源
- ExpressJS 有用资源
- ExpressJS - 快速指南
- ExpressJS - 有用资源
- ExpressJS - 讨论
ExpressJS - 脚手架
脚手架允许我们轻松创建Web应用程序的框架。我们手动创建公共目录,添加中间件,创建单独的路由文件等。脚手架工具为我们设置所有这些内容,以便我们可以直接开始构建应用程序。
我们将使用的脚手架工具称为Yeoman。它是一个为Node.js构建的脚手架工具,但也有几个其他框架的生成器(如Flask、Rails、Django等)。要安装Yeoman,请在您的终端中输入以下命令:
npm install -g yeoman
Yeoman使用生成器来构建应用程序。要查看可在npm上使用的Yeoman生成器,您可以点击此链接。在本教程中,我们将使用'generator-Express-simple'。要安装此生成器,请在您的终端中输入以下命令:
npm install -g generator-express-simple
要使用此生成器,请输入以下命令:
yo express-simple test-app
系统会询问您一些简单的问题,例如您想在应用程序中使用哪些内容。选择以下答案,或者如果您已经了解这些技术,那么您可以选择自己想要的方式。
express-simple comes with bootstrap and jquery [?] Select the express version you want: 4.x [?] Do you want an mvc express app: Yes [?] Select the css preprocessor you would like to use: sass [?] Select view engine you would like to use: jade [?] Select the build tool you want to use for this project: gulp [?] Select the build tool you want to use for this project: gulp [?] Select the language you want to use for the build tool: javascript create public/sass/styles.scss create public/js/main.js create views/layout.jade create views/index.jade create views/404.jade create app.js create config.js create routes/index.js create package.json create bower.json identical .bowerrc identical .editorconfig identical .gitignore identical .jshintrc create gulpfile.js I'm all done. Running bower install & npm install for you to install the required dependencies. If this fails, try running the command yourself.
然后,它将为您创建一个新的应用程序,安装所有依赖项,向您的应用程序添加一些页面(主页、404 未找到页面等),并为您提供一个目录结构来进行操作。
此生成器为我们创建了一个非常简单的结构。探索Express提供的许多生成器,并选择最适合您的一个。所有生成器的使用方法都相同。您需要安装生成器,使用Yeoman运行它;它会问您一些问题,然后根据您的回答创建应用程序的框架。
广告
