如何从命令行创建一个Express EJS项目?

时间:2022-02-12 15:06:21

I have tried

我有试过

express -e myproject

表达- e。

However this does not work as expected

然而,这并不像预期的那样有效

8 个解决方案

#1


15  

express --help

  Usage: express [options] [path]

  Options:
    -s, --sessions           add session support
    -t, --template <engine>  add template <engine> support (jade|ejs). default=jade
    -c, --css <engine>       add stylesheet <engine> support (stylus). default=plain css
    -v, --version            output framework version
    -h, --help               output help information

so, do >express -t ejs [path]

>express -t ejs [path]

#2


5  

How to install express from the command line using express-generator and use EJS template engine

如何使用express-generator从命令行安装express并使用EJS模板引擎


1) Install express-generator globally("-g") if you don't have it already

1)如果您还没有express-generator,请全局安装(“-g”)

npm install express-generator -g


2.1) Check available commands

2.1)检查可用命令

express -h 

Result(in express version: 4.13.4):

结果(express版本:4.13.4):

  Usage: express [options] [dir]

  Options:
-h, --help          output usage information
-V, --version       output the version number
-e, --ejs           add ejs engine support (defaults to jade)
    --hbs           add handlebars engine support
-H, --hogan         add hogan.js engine support
-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

2.2) Generate an Express app with chosen preferences

2.2)生成带有选定首选项的Express app

express --ejs --git my_app_with_ejs_and_gitignore

Result:

结果:

   create : my_app_with_ejs_and_gitignore
   create : my_app_with_ejs_and_gitignore/package.json
   create : my_app_with_ejs_and_gitignore/app.js
   create : my_app_with_ejs_and_gitignore/.gitignore
   create : my_app_with_ejs_and_gitignore/public
   create : my_app_with_ejs_and_gitignore/public/javascripts
   create : my_app_with_ejs_and_gitignore/public/images
   create : my_app_with_ejs_and_gitignore/public/stylesheets
   create : my_app_with_ejs_and_gitignore/public/stylesheets/style.css
   create : my_app_with_ejs_and_gitignore/routes
   create : my_app_with_ejs_and_gitignore/routes/index.js
   create : my_app_with_ejs_and_gitignore/routes/users.js
   create : my_app_with_ejs_and_gitignore/views
   create : my_app_with_ejs_and_gitignore/views/index.ejs
   create : my_app_with_ejs_and_gitignore/views/error.ejs
   create : my_app_with_ejs_and_gitignore/bin
   create : my_app_with_ejs_and_gitignore/bin/www

   install dependencies:
     $ cd my_app_with_ejs_and_gitignore && npm install

   run the app:
     $ DEBUG=my_app_with_ejs_and_gitignore:* npm start


3) Navigate into the app directory and use NPM to install dependencies

3)导航到app目录,使用NPM安装依赖项

cd my_app_with_ejs_and_gitignore
npm install


Result:

结果:

+-- body-parser@1.15.2
| +-- bytes@2.4.0
| +-- content-type@1.0.2
| +-- depd@1.1.0
| +-- http-errors@1.5.0
| | +-- inherits@2.0.1
| | +-- setprototypeof@1.0.1
| | `-- statuses@1.3.0
| +-- iconv-lite@0.4.13
| +-- on-finished@2.3.0
| | `-- ee-first@1.1.1
| +-- qs@6.2.0
| +-- raw-body@2.1.7
| | `-- unpipe@1.0.0
| `-- type-is@1.6.13
|   +-- media-typer@0.3.0
|   `-- mime-types@2.1.11
|     `-- mime-db@1.23.0
+-- cookie-parser@1.4.3
| +-- cookie@0.3.1
| `-- cookie-signature@1.0.6
+-- debug@2.2.0
| `-- ms@0.7.1
+-- ejs@2.4.2
+-- express@4.13.4
| +-- accepts@1.2.13
| | `-- negotiator@0.5.3
| +-- array-flatten@1.1.1
| +-- content-disposition@0.5.1
| +-- cookie@0.1.5
| +-- escape-html@1.0.3
| +-- etag@1.7.0
| +-- finalhandler@0.4.1
| +-- fresh@0.3.0
| +-- merge-descriptors@1.0.1
| +-- methods@1.1.2
| +-- parseurl@1.3.1
| +-- path-to-regexp@0.1.7
| +-- proxy-addr@1.0.10
| | +-- forwarded@0.1.0
| | `-- ipaddr.js@1.0.5
| +-- qs@4.0.0
| +-- range-parser@1.0.3
| +-- send@0.13.1
| | +-- destroy@1.0.4
| | +-- http-errors@1.3.1
| | +-- mime@1.3.4
| | `-- statuses@1.2.1
| +-- serve-static@1.10.3
| | `-- send@0.13.2
| |   +-- http-errors@1.3.1
| |   `-- statuses@1.2.1
| +-- utils-merge@1.0.0
| `-- vary@1.0.1
+-- morgan@1.7.0
| +-- basic-auth@1.0.4
| `-- on-headers@1.0.1
`-- serve-favicon@2.3.0


4) Start the server

4)启动服务器

DEBUG=my_app_with_ejs_and_gitignore:* npm start

Result:

结果:

my_app_with_ejs_and_gitignore@0.0.0 start C:\Users\Marian\OneDrive\Documente\Practice\Node\express_generator_2\my_app_with_ejs_and_gitignore
node ./bin/www
Sun, 31 Jul 2016 13:51:25 GMT my_app_with_ejs_and_gitignore:server Listening on port 3000


5) See the result in the browser
Open a browser and navigate to: http://localhost:3000/

5)在浏览器中查看结果,打开浏览器并导航到:http://localhost:3000/

The page should contain the following text:
Express
Welcome to Express

页面应该包含以下文本:表示欢迎表达

#3


3  

npm install -g express-generator

and then

然后

express -e project-name

this will create a project with ejs template engine

这将使用ejb模板引擎创建一个项目

#4


2  

  1. Install express globally npm install -g express
  2. 全球安装快递npm安装-g express
  3. In terminal, go to the directory in which you want your project to reside. If you are in the directory that you want the files to be in, just type express. If you want express to make a subfolder for the project, type express appname.
  4. 在终端中,转到希望项目驻留的目录。如果在希望文件所在的目录中,只需输入express。如果您希望express为项目创建子文件夹,请输入express appname。
  5. To install EJS, use npm install ejs
  6. 要安装EJS,请使用npm安装EJS。
  7. To configure EJS in your express project, you have to make sure you have the following line in your app.config function:

    要在express项目中配置EJS,您必须确保在app.config函数中有以下一行:

    app.set('view engine', 'ejs');
    

EDIT: As dmh2000 pointed out, you can also just do express -t ejs

编辑:正如dmh2000所指出的,您还可以做快递-t ejb

#5


2  

The option to use depends on the installed version of express (check express -V!)

使用的选项取决于已安装的express版本(请参阅express -V!)

It was changed somewhere around version 3.0.0alpha1.

它在3.0.0alpha1版本前后被修改过。

It used to be: express -t ejs, now it is: express -e or express --ejs

它曾经是:express -t ejb,现在是:express -e或express -ejs

Proof (from express Git repo):

证明(由Git express repo提供):

git log -S'--ejs' # Search for the change using pickaxe
git show 29508f1 # The commit
git cat-file blob 29508f1:package.json|grep version # express version

Morale: NodeJS modules are moving targets, always check their docs, especially after updating stuff.

士气:NodeJS模块正在移动目标,总是检查他们的文档,特别是在更新之后。

#6


2  

Express provides a generator (see instructions below), however for a batteries included generator, you might choose my express-no-stress generator.

Express提供了一个发电机(请参阅下面的说明),但是对于包含发电机的电池,您可以选择我的无压力表达式发电机。

Express-no-stress

Express-no-stress

Includes ES.next via Babel.js, structured logging with Pino, API validation and interactive documentation via Swagger, environment based config with dotenv, linting with ESLint, and Backpack powered builds.

包括ES。通过巴别塔下。js, Pino的结构化日志,API验证和交互文档,通过Swagger, dotenv的基于环境的配置,ESLint的lint,和背包驱动的构建。

Install

安装

npm install -g yo generator-express-no-stress

npm安装-g yo generator-express-no-stress

Generate Project

生成项目

yo express-no-stress myapp

哟express-no-stress myapp

Run

运行

npm run dev

npm运行开发


Or use the Express Generator that can be used as follows:

或使用下列快捷发电机:

Install

安装

npm install express-generator -g

npm安装express-generator - g

Generate Project

生成项目

express myapp

表达myapp

#7


1  

Make sure you have the express generator installed:

请确保安装了快递发电机:

npm install express-generator -g

then to start a project

然后开始一个项目。

express myproject

To display the help screen

显示帮助屏幕

express --h

I hope it helps

我希望这有助于

#8


1  

Just start you project with this command

只需使用此命令启动项目

express --view=ejs appName

don't forget to install express-generator globally by npm install -g express-generator

不要忘记通过npm安装-g express-generator在全球安装express-generator

#1


15  

express --help

  Usage: express [options] [path]

  Options:
    -s, --sessions           add session support
    -t, --template <engine>  add template <engine> support (jade|ejs). default=jade
    -c, --css <engine>       add stylesheet <engine> support (stylus). default=plain css
    -v, --version            output framework version
    -h, --help               output help information

so, do >express -t ejs [path]

>express -t ejs [path]

#2


5  

How to install express from the command line using express-generator and use EJS template engine

如何使用express-generator从命令行安装express并使用EJS模板引擎


1) Install express-generator globally("-g") if you don't have it already

1)如果您还没有express-generator,请全局安装(“-g”)

npm install express-generator -g


2.1) Check available commands

2.1)检查可用命令

express -h 

Result(in express version: 4.13.4):

结果(express版本:4.13.4):

  Usage: express [options] [dir]

  Options:
-h, --help          output usage information
-V, --version       output the version number
-e, --ejs           add ejs engine support (defaults to jade)
    --hbs           add handlebars engine support
-H, --hogan         add hogan.js engine support
-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

2.2) Generate an Express app with chosen preferences

2.2)生成带有选定首选项的Express app

express --ejs --git my_app_with_ejs_and_gitignore

Result:

结果:

   create : my_app_with_ejs_and_gitignore
   create : my_app_with_ejs_and_gitignore/package.json
   create : my_app_with_ejs_and_gitignore/app.js
   create : my_app_with_ejs_and_gitignore/.gitignore
   create : my_app_with_ejs_and_gitignore/public
   create : my_app_with_ejs_and_gitignore/public/javascripts
   create : my_app_with_ejs_and_gitignore/public/images
   create : my_app_with_ejs_and_gitignore/public/stylesheets
   create : my_app_with_ejs_and_gitignore/public/stylesheets/style.css
   create : my_app_with_ejs_and_gitignore/routes
   create : my_app_with_ejs_and_gitignore/routes/index.js
   create : my_app_with_ejs_and_gitignore/routes/users.js
   create : my_app_with_ejs_and_gitignore/views
   create : my_app_with_ejs_and_gitignore/views/index.ejs
   create : my_app_with_ejs_and_gitignore/views/error.ejs
   create : my_app_with_ejs_and_gitignore/bin
   create : my_app_with_ejs_and_gitignore/bin/www

   install dependencies:
     $ cd my_app_with_ejs_and_gitignore && npm install

   run the app:
     $ DEBUG=my_app_with_ejs_and_gitignore:* npm start


3) Navigate into the app directory and use NPM to install dependencies

3)导航到app目录,使用NPM安装依赖项

cd my_app_with_ejs_and_gitignore
npm install


Result:

结果:

+-- body-parser@1.15.2
| +-- bytes@2.4.0
| +-- content-type@1.0.2
| +-- depd@1.1.0
| +-- http-errors@1.5.0
| | +-- inherits@2.0.1
| | +-- setprototypeof@1.0.1
| | `-- statuses@1.3.0
| +-- iconv-lite@0.4.13
| +-- on-finished@2.3.0
| | `-- ee-first@1.1.1
| +-- qs@6.2.0
| +-- raw-body@2.1.7
| | `-- unpipe@1.0.0
| `-- type-is@1.6.13
|   +-- media-typer@0.3.0
|   `-- mime-types@2.1.11
|     `-- mime-db@1.23.0
+-- cookie-parser@1.4.3
| +-- cookie@0.3.1
| `-- cookie-signature@1.0.6
+-- debug@2.2.0
| `-- ms@0.7.1
+-- ejs@2.4.2
+-- express@4.13.4
| +-- accepts@1.2.13
| | `-- negotiator@0.5.3
| +-- array-flatten@1.1.1
| +-- content-disposition@0.5.1
| +-- cookie@0.1.5
| +-- escape-html@1.0.3
| +-- etag@1.7.0
| +-- finalhandler@0.4.1
| +-- fresh@0.3.0
| +-- merge-descriptors@1.0.1
| +-- methods@1.1.2
| +-- parseurl@1.3.1
| +-- path-to-regexp@0.1.7
| +-- proxy-addr@1.0.10
| | +-- forwarded@0.1.0
| | `-- ipaddr.js@1.0.5
| +-- qs@4.0.0
| +-- range-parser@1.0.3
| +-- send@0.13.1
| | +-- destroy@1.0.4
| | +-- http-errors@1.3.1
| | +-- mime@1.3.4
| | `-- statuses@1.2.1
| +-- serve-static@1.10.3
| | `-- send@0.13.2
| |   +-- http-errors@1.3.1
| |   `-- statuses@1.2.1
| +-- utils-merge@1.0.0
| `-- vary@1.0.1
+-- morgan@1.7.0
| +-- basic-auth@1.0.4
| `-- on-headers@1.0.1
`-- serve-favicon@2.3.0


4) Start the server

4)启动服务器

DEBUG=my_app_with_ejs_and_gitignore:* npm start

Result:

结果:

my_app_with_ejs_and_gitignore@0.0.0 start C:\Users\Marian\OneDrive\Documente\Practice\Node\express_generator_2\my_app_with_ejs_and_gitignore
node ./bin/www
Sun, 31 Jul 2016 13:51:25 GMT my_app_with_ejs_and_gitignore:server Listening on port 3000


5) See the result in the browser
Open a browser and navigate to: http://localhost:3000/

5)在浏览器中查看结果,打开浏览器并导航到:http://localhost:3000/

The page should contain the following text:
Express
Welcome to Express

页面应该包含以下文本:表示欢迎表达

#3


3  

npm install -g express-generator

and then

然后

express -e project-name

this will create a project with ejs template engine

这将使用ejb模板引擎创建一个项目

#4


2  

  1. Install express globally npm install -g express
  2. 全球安装快递npm安装-g express
  3. In terminal, go to the directory in which you want your project to reside. If you are in the directory that you want the files to be in, just type express. If you want express to make a subfolder for the project, type express appname.
  4. 在终端中,转到希望项目驻留的目录。如果在希望文件所在的目录中,只需输入express。如果您希望express为项目创建子文件夹,请输入express appname。
  5. To install EJS, use npm install ejs
  6. 要安装EJS,请使用npm安装EJS。
  7. To configure EJS in your express project, you have to make sure you have the following line in your app.config function:

    要在express项目中配置EJS,您必须确保在app.config函数中有以下一行:

    app.set('view engine', 'ejs');
    

EDIT: As dmh2000 pointed out, you can also just do express -t ejs

编辑:正如dmh2000所指出的,您还可以做快递-t ejb

#5


2  

The option to use depends on the installed version of express (check express -V!)

使用的选项取决于已安装的express版本(请参阅express -V!)

It was changed somewhere around version 3.0.0alpha1.

它在3.0.0alpha1版本前后被修改过。

It used to be: express -t ejs, now it is: express -e or express --ejs

它曾经是:express -t ejb,现在是:express -e或express -ejs

Proof (from express Git repo):

证明(由Git express repo提供):

git log -S'--ejs' # Search for the change using pickaxe
git show 29508f1 # The commit
git cat-file blob 29508f1:package.json|grep version # express version

Morale: NodeJS modules are moving targets, always check their docs, especially after updating stuff.

士气:NodeJS模块正在移动目标,总是检查他们的文档,特别是在更新之后。

#6


2  

Express provides a generator (see instructions below), however for a batteries included generator, you might choose my express-no-stress generator.

Express提供了一个发电机(请参阅下面的说明),但是对于包含发电机的电池,您可以选择我的无压力表达式发电机。

Express-no-stress

Express-no-stress

Includes ES.next via Babel.js, structured logging with Pino, API validation and interactive documentation via Swagger, environment based config with dotenv, linting with ESLint, and Backpack powered builds.

包括ES。通过巴别塔下。js, Pino的结构化日志,API验证和交互文档,通过Swagger, dotenv的基于环境的配置,ESLint的lint,和背包驱动的构建。

Install

安装

npm install -g yo generator-express-no-stress

npm安装-g yo generator-express-no-stress

Generate Project

生成项目

yo express-no-stress myapp

哟express-no-stress myapp

Run

运行

npm run dev

npm运行开发


Or use the Express Generator that can be used as follows:

或使用下列快捷发电机:

Install

安装

npm install express-generator -g

npm安装express-generator - g

Generate Project

生成项目

express myapp

表达myapp

#7


1  

Make sure you have the express generator installed:

请确保安装了快递发电机:

npm install express-generator -g

then to start a project

然后开始一个项目。

express myproject

To display the help screen

显示帮助屏幕

express --h

I hope it helps

我希望这有助于

#8


1  

Just start you project with this command

只需使用此命令启动项目

express --view=ejs appName

don't forget to install express-generator globally by npm install -g express-generator

不要忘记通过npm安装-g express-generator在全球安装express-generator