0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

オライリージャパン「Node.jsプロジェクト」詰まりどころ

0
Last updated at Posted at 2026-08-30

2026年7月1日に出版されたオライリージャパン「Node.jsプロジェクト」で詰まった箇所とその解決方法をまとめました。

お知らせ(採用情報)

AppTime では一緒に働くメンバーを募集しております。
詳しくは採用情報ページをご確認ください。

みなさまからのご応募をお待ちしております。

3章 Node Webサーバーの作成

54ページ 例3-8

app.get("/", (req, reply) => {
  reply.view("views/index.ejs", { name: "What's Fare is Fair"});
});
app.get("/menu", (req, reply) => {
  reply.view("views/menu.ejs", { menuItems });
});

下記のようにしないとエラーが出ました

app.get("/", async (req, reply) => {
  reply.viewAsync("views/index.ejs", { name: "What's Fare is Fair"});
});

app.get("/menu", async (req, reply) => {
  reply.viewAsync("views/menu.ejs", { menuItems });
});

54ページ以前では当該コードが非同期になっているが、ここでは特に記述なくしれっと同期関数になっているため起こったエラーでした。
非同期関数ではreply.viewではなくreply.viewAyncでテンプレートを返さないとならないようです。

5章 コンテンツアグリゲーター

92ページ 例5-3

const url = "https://www.bonappetit.com/feed/recipes-rss-feed/rss";
const {title, items} = await parser.parseURL(url);
console.log(title);
const results = items.map(({title, link}) => ({title, link}));
console.table(results);

とありますが、urlに代入されたリンクが現在RSSに非対応となっているようです。
代わりに https://www.bbcgoodfood.com/feed を代入することでresultsを取得できました。

6章 図書館API

111ページ 例6-3

app.get("/", async (_request, reply) => {
  reply.send({ message: "ok"});
});

app.setNotFoundHandler((request, reply) => {
  const { message, statusCode } = request.error || {};
  reply.status(statusCode || 500).send({ message });
});

このコードは108ページの例6-1にあるFastifyアプリケーションをインスタンス化しリクエストのリッスンを開始するコードよりも上に記述する必要があります。
上から順にコードを実行するにあたって、すでにリッスン中のインスタンスにルートを追加できないためエラーが出るようです。

現在11章まで完了しましたがここに挙げたもの以外で詰まったところや誤植は特にありませんでした。
他に詰まる箇所が見つかれば解決方法を投稿します。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?