Help us understand the problem. What is going on with this article?

expressパッケージとコマンドのインストール

More than 5 years have passed since last update.

expressパッケージのインストール

expressのグローバルインストール。

$ npm install -g express

グローバルインストールした場合はNODE_PATHにnode_modulesのパスをセットしておく。

# node_modules
export NODE_PATH=/usr/local/lib/node_modules

hello worldで動作確認します。

app.js
app = require('express')();

app.get('/', function(req, res){
        res.send('hello world');
    });

app.listen(3000);

上記app.jsを作成してからnodeコマンドでWebサーバーを起動。ブラウザでhttp://localhost:3000 を表示できます。

$ node app.js

expressコマンド

expressコマンドはexpress-generatorパッケージでインストールできます。

$ npm install -g express-generator

expressコマンドを実行すると基本的なファイルが生成される。

$ express

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

   install dependencies:
     $ cd . && npm install

   run the app:
     $ DEBUG=my-application ./bin/www

npm installで依存するパッケージを取得した後、./bin/wwwでWebサーバーの起動です。

pakiln
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした