server.js
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[Node.js化]]
** [[基本的な流れ]] [#y69caab5]
import express from 'express';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { port, routePrefix, basePath } from './config.js';
const app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// View Engine Setup
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// 静的ファイルのマウント
app.use(basePath, express.static(path.join(__dirname, 'p...
app.use('/media', express.static(path.join(__dirname, 'p...
// 動的ルートの自動登録
const routeDir = path.join(__dirname, 'routes');
fs.readdirSync(routeDir).forEach(file => {
if (file.endsWith('.js')) {
import(`./routes/${file}`).then(module => {
app.use('/' + file.replace('.js', ''), module.defa...
});
}
});
app.listen(port, () => {
console.log(`Tennis app listening at http://localhost:...
});
** [[views(テンプレート)を使うための Express 側設定]] [...
** [[ルーティング(routes)でベースパスを使うには]] [#c7a...
** [[静的ファイルへのアクセス]] [#jdcae473]
** [[静的ファイルの読み込み]] [#t6c5d720]
終了行:
[[Node.js化]]
** [[基本的な流れ]] [#y69caab5]
import express from 'express';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { port, routePrefix, basePath } from './config.js';
const app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// View Engine Setup
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// 静的ファイルのマウント
app.use(basePath, express.static(path.join(__dirname, 'p...
app.use('/media', express.static(path.join(__dirname, 'p...
// 動的ルートの自動登録
const routeDir = path.join(__dirname, 'routes');
fs.readdirSync(routeDir).forEach(file => {
if (file.endsWith('.js')) {
import(`./routes/${file}`).then(module => {
app.use('/' + file.replace('.js', ''), module.defa...
});
}
});
app.listen(port, () => {
console.log(`Tennis app listening at http://localhost:...
});
** [[views(テンプレート)を使うための Express 側設定]] [...
** [[ルーティング(routes)でベースパスを使うには]] [#c7a...
** [[静的ファイルへのアクセス]] [#jdcae473]
** [[静的ファイルの読み込み]] [#t6c5d720]
ページ名: