Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Nodejs Express code to redirect mobile user agets
var express = require('express'),
app = express();
app.get('/', function(req, res){
var ua = req.header('user-agent');
// Check the user-agent string to identyfy the device.
if(/mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile|ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(ua)) {
res.sendfile(__dirname + '/mobile.html');
} else {
res.sendfile(__dirname + '/index.html');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment