LoginSignup
13
11

More than 5 years have passed since last update.

Connectを使った静的ファイル配信サーバが動かなくなった

Posted at

概要

最近、Connect3になってから、仕様がだいぶ変わったらしい。
前に書いたスクリプトが以下のようなエラーを出力して動かなくなった。

has no method 'static'

2.xx

以下のようにバージョンを指定して、インストールする。

$ npm install connect@2.X.X

前のコードが使用できる。

server.js
var connect = require('connect');
connect.createServer(
    connect.static(__dirname)
).listen(5000);

3.xx

最新版を使う場合は、serve-staticをインストールする。

$ npm install serve-static

コードは以下のようになる。

server.js
var connect = require('connect'),
    serveStatic = require('serve-static');

var app = connect();

app.use(serveStatic(__dirname));
app.listen(5000);

参考

nodejs connect cannot find static
http://stackoverflow.com/questions/24346161/nodejs-connect-cannot-find-static

13
11
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
13
11