Expressjs-scaffolding

提供:Dev Guides
移動先:案内検索

ExpressJS-足場

足場を使用すると、Webアプリケーションのスケルトンを簡単に作成できます。 パブリックディレクトリを手動で作成し、ミドルウェアを追加し、個別のルートファイルを作成します。 足場ツールがこれらすべてをセットアップするため、アプリケーションの構築を直接開始できます。

使用する足場は Yeoman と呼ばれます。 Node.js 用に構築された足場ツールですが、他のいくつかのフレームワーク(フラスコ、レール、ジャンゴなど)のジェネレーターもあります。 Yeomanをインストールするには、ターミナルで次のコマンドを入力します-

npm install -g yeoman

Yeomanは、ジェネレーターを使用してアプリケーションの足場を作ります。 Yeomanで使用する npm で利用可能なジェネレーターを確認するには、このhttp://yeoman.io/generators/[リンク]をクリックしてください。 このチュートリアルでは、_ '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を使用して実行する必要があります。いくつかの質問をし、答えに基づいてアプリケーションのスケルトンを作成します。