0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

node.jsのExpressを導入するときの手順メモAzure前提

Last updated at Posted at 2020-11-06

概要

自分用の( ..)φメモメモ。
node.jsのexpressを新規に導入するときの手順。
AzureのWebAppで動かす前提で、TDD想定でsrcとtestフォルダに分けるものとする。
必要最小限。test側のモジュール導入は省略。

手順のメモ

express-generator はグローバルで導入済みとする。

※未導入の場合は以下で導入する。

npm install -g  express-generator 

※利用を終えて、気になるようなら本記事に記載の手順をすべて実行後に以下のコマンドでアンインストールする。

npm uninstall -g  express-generator 

Expressのスケルトン作成してAzure向け且つTDD向けにファイル移動する

express myapp --no-view
mkdir src
mkdir test
copy myapp\bin\www .\server.js
xcopy myapp\public .\src\public\
xcopy myapp\routes .\src\routes\
copy myapp\app.js  .\src\
npm init

server.jsのファイル書き換える

var app = require('../app');
// ↓
var app = require('./src/app');

package.jsonに、myapp配下のそれから以下をコピペする

  "dependencies": {
    "cookie-parser": "~1.4.4",
    "debug": "~2.6.9",
    "express": "~4.16.1",
    "morgan": "~1.9.1"
  },

不要な作業フォルダを削除して、必要なモジュールを追加インストールする

rmdir /s /q myapp
npm install
npm i   node-dev cross-env --save-dev

package.jsonのscript欄に、debug実行用にコマンドを追加する

"dev": "cross-env DEBUG=myapp:* node-dev server.js",

以上ー。

補足

testコマンドまで含めた導入済み版はこちらを参照。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?