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

Raspberry PiにNode.jsとExpressをインストールする方法

Last updated at Posted at 2025-08-22

この記事では、Raspberry PiにNode.jsExpressをインストールし、サンプルアプリを動かすまでの手順を解説します。

対象環境

  • Raspberry Pi 4 (他モデルでも問題なし)
  • Raspberry Pi OS Bookworm(最新版)
  • ネットワーク接続があること
  • ターミナル操作ができること(SSH または HDMI 接続)
  • Raspberry Piのセットアップが完了していること

手順の全体像

  1. システムのアップデート
  2. Node.js のインストール
  3. Express の導入
  4. サンプルアプリの起動

1. システムのアップデート

まずはパッケージを更新します。

sudo apt update

2. Node.js のインストール

最新の LTS版 Node.js をインストールします。

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

npm を最新版に更新します。

sudo npm install -g npm@latest

バージョン確認します。

user@raspberrypi:~ $ node -v
v22.18.0
user@raspberrypi:~ $ npm -v
11.5.2

3. Express の導入

Node.js が使えるようになったら、Express を使ってアプリを作ります。
まずは express-generator を使ってサンプルを生成します。

user1001@raspberrypi:~ $ npx express-generator --view=ejs sample-app
Need to install the following packages:
express-generator@4.16.1
Ok to proceed? (y) y
〜

アプリの依存関係をインストールします。

cd sample-app
npm install

4. サンプルアプリの起動

npm startコマンドでサンプルアプリを起動します。
起動すると以下のようなメッセージが出ます。

user@raspberrypi:~/sample-app $ npm start

> sample-app@0.0.0 start
> node ./bin/www

ブラウザで以下のURLにアクセスしてください。

http://<Raspberry PiのIPアドレス>:3000

スクリーンショット 2025-08-22 10.33.33.png
画像の様に「Welcome to Express」と表示されれば成功です

まとめ

Raspberry Piを使えば、低コストで手軽にWebアプリの開発環境を構築できます。ぜひ試してみてください!

よろしければ、いいね、ストック、コメントいただけますと幸いです。

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