Welcome aboard! We are happy you are here and wish you good net-raft!
// at first you install "npm i --save express express-device" in node.js command prompt
// this put into detect.js
var express = require('express');
var app = express();
var device = require('express-device');
app.use(device.capture());
app.get('/mydevice',function(req,res) {
res.send(req.device.type.toUpperCase()); // Possible Values: desktop, tv, tablet, phone, bot or car
});
app.listen(3000);
console.log("Listening to Port 3000");
// then put this url into browser http://localhost:3000/mydevice
// at first you install "npm install express-useragent --save","npm install yamlparser --save","npm install request --save" in node.js command prompt
var express = require('express');
var app = express(),
useragent = require('express-useragent');
app.get('/', function(req, res){
var source = req.headers['user-agent'];
var info = useragent.parse(source);
var device = "";
if (info['isDesktop'] == true) {device = "desktop"}
else if (info['isMobile'] == true) {device = "mobile"}
else {device = "something else"}
res.send(device)
})
app.listen(3000);
console.log("Listening to Port 3000");
The most helpful NODEJS solutions
get user ipNODEJS Click to see more ... 7.5K 1.7K