首先拷贝express官网的一篇文章:

(http://expressjs.com/en/starter/generator.html )

Express application generator

Use the application generator tool, express-generator, to quickly create an application skeleton.

The express-generator package installs the express command-line tool. Use the following command to do so:

$ npm install express-generator -g

Display the command options with the -h option:

$ express -h

 

Usage: express [options] [dir]

 

Options:

 

-h, --help output usage information

--version output the version number

-e, --ejs add ejs engine support

--hbs add handlebars engine support

--pug add pug engine support

-H, --hogan add hogan.js engine support

-v, --view <engine> add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)

-c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)

--git add .gitignore

-f, --force force on non-empty directory

For example, the following creates an Express app named myapp. The app will be created in a folder named myapp in the current working directory and the view engine will be set to Pug:

$ express --view=pug myapp

 

create : myapp

create : myapp/package.json

create : myapp/app.js

create : myapp/public

create : myapp/public/javascripts

create : myapp/public/images

create : myapp/routes

create : myapp/routes/index.js

create : myapp/routes/users.js

create : myapp/public/stylesheets

create : myapp/public/stylesheets/style.css

create : myapp/views

create : myapp/views/index.pug

create : myapp/views/layout.pug

create : myapp/views/error.pug

create : myapp/bin

create : myapp/bin/www

Then install dependencies:

$ cd myapp

$ npm install

On MacOS or Linux, run the app with this command:

$ DEBUG=myapp:* npm start

On Windows, use this command:

> set DEBUG=myapp:* & npm start

Then load http://localhost:3000/ in your browser to access the app.

The generated app has the following directory structure:

.

├── app.js

├── bin

│ └── www

├── package.json

├── public

│ ├── images

│ ├── javascripts

│ └── stylesheets

│ └── style.css

├── routes

│ ├── index.js

│ └── users.js

└── views

├── error.pug

├── index.pug

└── layout.pug

 

7 directories, 9 files

 

这里需要注意的是:

  1. 需要把npm的路径加入到系统的环境变量中去。不然的话即使安装了express-generator,命令行也无法识别express命令。加入环境变量后要重启命令行才可以。

    Npm的路径通常为c:\users\<user name>\appdata\roaming\npm

  2. 然后按照上面文章中的步骤执行即可, 里面的—view可以选择jade,这个我比较熟悉。

Express application generator的使用的更多相关文章

  1. [转] Creating a Simple RESTful Web App with Node.js, Express, and MongoDB

    You can find/fork the sample project on GitHub Hey! This and all my other tutorials will soon be mov ...

  2. 基于express框架的应用程序骨架生成器介绍

    作者:zhanhailiang 日期:2014-11-09 本文将介绍怎样使用express-generator工具高速生成基于express框架的应用程序骨架: 1. 安装express-gener ...

  3. Moving to Express 4

    http://expressjs.com/guide/migrating-4.html Moving to Express 4 Overview Express 4 is a breaking cha ...

  4. express@4.0.*

    $ sudo npm install -g express the installation goes fine. But when I try to create a project with ex ...

  5. 下篇:express、koa1、koa2的中间件原理

    本作品采用知识共享署名 4.0 国际许可协议进行许可.转载联系作者并保留声明头部与原文链接https://luzeshu.com/blog/express-koa 本博客同步在http://www.c ...

  6. nodejs开发 express路由与中间件

    路由 通常HTTP URL的格式是这样的: http://host[:port][path] http表示协议. host表示主机. port为端口,可选字段,不提供时默认为80. path指定请求资 ...

  7. [译]简单得不得了的教程-一步一步用 NODE.JS, EXPRESS, JADE, MONGODB 搭建一个网站

    原文: http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/ 原文的源代码在此 太多的教程教你些一个Hello, World!了, ...

  8. express 框架之 路由与中间件

    1.  什么是router路径,什么是middleware? 我们输入www.baidu.com 来访问百度的主页,浏览器会自动转换为 http://www.baidu.com:80/(省略一些参数) ...

  9. nodejs express 框架解密2-如何创建一个app

    本文是基于express 3.4.6 的 1.在我们的app.js 文件里面有这么几行 http.createServer(app).listen(app.get('port'), function( ...

随机推荐

  1. perl 信号

    来自:http://www.bagualu.net/wordpress/?p=1628 使用signal,能让你的程序功能更丰富.要在Linux下列出所有的signal, 利用kill -l即可. 下 ...

  2. python脚本从excel表到处数据,生成指定格式的文件

    #coding:gbk #导入处理excel的模块 import xlrd #定义哪些字段须要推断,仅仅支持时间字段 toSureColArray = ['CREATE_TIME','MODIFY_T ...

  3. AngularJS报错:[$injector:unpr] Unknown provider: $templateRequestProvider

    在页面中由上到下引用了: angular.js angular-route.js 创建model的时候也写明了依赖: var someApp = angular.module('someApp',[' ...

  4. Android:intent的基础

    只有一个活动的应用也太简单了吧?没错,你的追求应该更高一点.不管你想创建多少 个活动,方法都和上一节中介绍的是一样的.唯一的问题在于,你在启动器中点击应用的图 标只会进入到该应用的主活动,那么怎样才能 ...

  5. 让DELPHI自带的richedit控件显示图片

    让DELPHI自带的richedit控件显示图片 unit RichEx; { 2005-03-04 LiChengbin Added: Insert bitmap or gif into RichE ...

  6. HelloWorld 之JasperReports初步

    在企业应用系统中,经常要输出各种格式的数据报表. 著名的开源项目<JasperReports可以很好的解决这个问题. 使用JasperReports可以在预先设定好格式的报表基础上进行数据的填充 ...

  7. Android项目更换开发环境时出现的 java.lang.VerifyError 异常解决办法

    from://http://blog.csdn.net/wudiwo/article/details/7548451 项目是从同事的电脑上直接拷贝过来的,项目里面的jar包是在项目跟下libs里面存放 ...

  8. jquery.timers使用说明

    jQuery Timers提供了三个函式 1. everyTime(时间间隔, [定时器名称], 函式名称, [次数限制], [等待函式程序完成])2. oneTime(时间间隔, [定时器名称],  ...

  9. [Android Pro] 开发一流的 Android SDK:Fabric SDK 的创建经验

    cp from : https://academy.realm.io/cn/posts/oredev-ty-smith-building-android-sdks-fabric/ Ty Smith T ...

  10. Git: Push rejected 的解决方案

    Push rejected: Push to origin/master was rejected 首先,git init (在工程文件夹下) git remote add [-t <branc ...