LoginSignup
41

More than 5 years have passed since last update.

Organization

Express4でBASIC認証をする

Express3時代とは違い、Express4ではいろんな機能が外部モジュールに分割されています。なので、必要な物はrequireしなくてはならない。

Express3時代のBASIC認証

app.use(express.basicAuth('username', 'password'));

Express4時代のBASIC認証

まず、basic-auth-connectをインストール。(実際には、package.jsonに記述してnpm installだけど)

$ npm install basic-auth-connect

後は、今までと書き方はほぼ変わらないです。

var basicAuth = require('basic-auth-connect');
app.use(basicAuth('username', 'password'));

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
What you can do with signing up
41