connect-mobile-detection

Connect middleware to check useragent for mobile or tablet devices.

Usage no npm install needed!

<script type="module">
  import connectMobileDetection from 'https://cdn.skypack.dev/connect-mobile-detection';
</script>

README

Connect Mobile Detection

Build Status

Connect middleware which uses the client useragent to detect mobile and tablet devices.

Adds boolean mobile and tablet properties to req.

Note

It is not always wise to rely on useragents to determine mobile and tablet clients.

Usage

For all routes.

var checkMobile = require('connect-mobile-detection');
...
app.use(checkMobile());
...
// Within any route.
  console.log(req.mobile);
  console.log(req.tablet);

For single routes using Express.

var checkMobile = require('connect-mobile-detection');
...
app.get('/', checkMobile(), function (req, res) {
  console.log(req.mobile);
  console.log(req.tablet);
});

License

Licensed MIT unless otherwise noted. See LICENSE file.

This module uses public domain code from Chad Smith's detectmobilebrowsers.com project.