TheBlackBenzKid TheBlackBenzKid -3 years ago 111
Node.js Question

How to host an adaptive website in NodeJS and Express?

I am planning to make an ecommerce application however I do not wish to have a responsive site. The desktop site will support tablet and will be some what responsive.

The mobile site will be a dedicated mobile site with a seperate view. I normally use Laravel or a PHP approach to detect the mobile and do server-side rendering based on the device (some people call these adaptive sites or

m dot com

My question is. Using Express, Node and a JavaScript approach can I achieve this?

All users who visit will either site a mobile code or a desktop code depending on device. We currently do this at (See Chrome and change device and the code base changes)

Answer Source

Yeah, of course you can do it. As you do it in PHP or any other language you need to find device type using user agent from the request. Below code uses express-device to render different ejs files.

var express = require('express');
var app = express();

// set the view engine to ejs
app.set('view engine', 'ejs');

var device = require('express-device');

app.get('/hello',function(req,res) {
   if(req.device.type === 'phone'){
   } else {

console.log("Listening to Port 3000");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download