mirror of
				https://github.com/goldbergyoni/nodebestpractices.git
				synced 2025-11-04 04:13:54 +08:00 
			
		
		
		
	Merge pull request #120 from YukiOta/1-4_Separate_Express_app_and_server_japanese
1 4 separate express app and server japanese
This commit is contained in:
		@ -92,13 +92,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<br/><br/>
 | 
					<br/><br/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## ![✔] 1.4 Separate Express 'app' and 'server'
 | 
					## ![✔] 1.4 Express の「アプリ」と「サーバー」を分離する
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**TL;DR:** Avoid the nasty habit of defining the entire [Express](https://expressjs.com/) app in a single huge file - separate your 'Express' definition to at least two files: the API declaration (app.js) and the networking concerns (WWW). For even better structure, locate your API declaration within components
 | 
					**TL;DR:** [Express](https://expressjs.com/) のアプリ全体を単一の巨大なファイルで定義するという厄介な習慣を回避します。- 「Express」の定義を、API 宣言( app.js )とネットワーク関連( WWW )の少なくとも2つのファイルに分離してください。より良い構造にするためには、API 宣言をコンポーネント内に配置してください。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**Otherwise:** Your API will be accessible for testing via HTTP calls only (slower and much harder to generate coverage reports). It probably won't be a big pleasure to maintain hundreds of lines of code in a single file
 | 
					**さもないと:** API は HTTP 呼び出しのみでテストにアクセスできるようになります(カバレッジレポートを生成するのがより遅く、はるかに困難になります)。何百行ものコードを一つのファイルで管理するのは、おそらく大きな喜びではないでしょう。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
🔗 [**Read More: separate Express 'app' and 'server'**](/sections/projectstructre/separateexpress.md)
 | 
					🔗 [**さらに読む: Express の「アプリ」と「サーバー」を分離する**](/sections/projectstructre/separateexpress.japanese.md)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<br/><br/>
 | 
					<br/><br/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,14 +1,14 @@
 | 
				
			|||||||
# Separate Express 'app' and 'server'
 | 
					# Express の「アプリ」と「サーバー」を分離する
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<br/><br/>
 | 
					<br/><br/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### One Paragraph Explainer
 | 
					### 一段落説明
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The latest Express generator comes with a great practice that is worth to keep - the API declaration is separated from the network related configuration (port, protocol, etc). This allows testing the API in-process, without performing network calls, with all the benefits that it brings to the table: fast testing execution and getting coverage metrics of the code. It also allows deploying the same API under flexible and different network conditions. Bonus: better separation of concerns and cleaner code
 | 
					最新の Express ジェネレーターは、維持する価値がある素晴らしいプラクティスが付属しています。- API 宣言はネットワーク関連の設定 (ポート、プロトコルなど) から分離されています。これにより、ネットワークコールを実行せずに API をインプロセスでテストすることができ、高速なテスト実行やコードのカバレッジメトリクスの取得などのメリットが得られます。 また、柔軟で異なるネットワーク条件の下で同じ API をデプロイすることができます。ボーナス:懸念事項のより良い分離とよりクリーンなコード
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<br/><br/>
 | 
					<br/><br/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Code example: API declaration, should reside in app.js/app.ts
 | 
					### コード例: API 宣言は app.js/app.ts にあるべき
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```javascript
 | 
					```javascript
 | 
				
			||||||
const app = express();
 | 
					const app = express();
 | 
				
			||||||
@ -17,7 +17,7 @@ app.use('/api/events', events.API);
 | 
				
			|||||||
app.use('/api/forms', forms);
 | 
					app.use('/api/forms', forms);
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Code example: Server network declaration, should reside in /bin/www
 | 
					### コード例: サーバーネットワーク定義は /bin/www にあるべき
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<details>
 | 
					<details>
 | 
				
			||||||
<summary><strong>Javascript</strong></summary>
 | 
					<summary><strong>Javascript</strong></summary>
 | 
				
			||||||
@ -51,7 +51,7 @@ const server = http.createServer(app);
 | 
				
			|||||||
```
 | 
					```
 | 
				
			||||||
</details>
 | 
					</details>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Example: test your API in-process using supertest (popular testing package)
 | 
					### 例: supertest (一般的なテストパッケージ) を使用して API をインプロセスでテストする
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<details>
 | 
					<details>
 | 
				
			||||||
<summary><strong>Javascript</strong></summary>
 | 
					<summary><strong>Javascript</strong></summary>
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user