LoginSignup
39
41

More than 5 years have passed since last update.

Express4でBASIC認証をする

Posted at

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'));
39
41
1

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
39
41