node.jsで-bash: express: command not foundが出たときの対処法

node.jsを使っていて、expressフレームワークをインストールした後雛形をインストールしようとするとエラーがでます。

[logw@dns html]$ express -t ejs firstapp
-bash: express: command not found

え?コマンドがない?うーん。。。参考サイトには書いてあるんだけどな・・・調べてみたらNode.js expressコマンドがインストールされないさんに載っていました。

sudo npm install -g express-generator


これを実行。そうすることでexpressコマンドが使えるようになります。
インストール後

[logw@dns html]$ express -t ejs firstapp

create : firstapp
create : firstapp/package.json
create : firstapp/app.js
create : firstapp/public
create : firstapp/public/stylesheets
create : firstapp/public/stylesheets/style.css
create : firstapp/routes
create : firstapp/routes/index.js
create : firstapp/routes/users.js
create : firstapp/views
create : firstapp/views/index.jade
create : firstapp/views/layout.jade
create : firstapp/views/error.jade
create : firstapp/bin
create : firstapp/bin/www

install dependencies:
$ cd firstapp && npm install

run the app:
$ DEBUG=firstapp:* ./bin/www

create : firstapp/public/javascripts
create : firstapp/public/images

とちゃんとコマンドが使えるようになりました。

個人支援・寄付について

サイトラボでは個人支援・寄付を受けております。ご協力いただける方はお願いいたします。当サイトではビットコインで受け付けております。

  • ビットコイン:3LHnADwZwUbic2L45EnVJEykiG6KfbqrwS