NODEJS parse json keys agent nodejs - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

how to parse the json keys of user agent in nodejs ?


 157

NODEJS


1

// at first you install "npm install express-useragent --save","npm install yamlparser --save","npm install request --save" in node.js command prompt

//put this code into test.js

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);

// all of json user-agent output
{"isAuthoritative":true,"isMobile":false,"isTablet":false,"isiPad":false,"isiPod":false,"isiPhone":false,"isAndroid":false,"isBlackberry":false,"isOpera":false,"isIE":true,"isEdge":false,"isIECompatibilityMode":false,"isSafari":false,"isFirefox":false,"isWebkit":false,"isChrome":false,"isKonqueror":false,"isOmniWeb":false,"isSeaMonkey":false,"isFlock":false,"isAmaya":false,"isPhantomJS":false,"isEpiphany":false,"isDesktop":true,"isWindows":true,"isLinux":false,"isLinux64":false,"isMac":false,"isChromeOS":false,"isBada":false,"isSamsung":false,"isRaspberry":false,"isBot":false,"isCurl":false,"isAndroidTablet":false,"isWinJs":false,"isKindleFire":false,"isSilk":false,"isCaptive":false,"isSmartTV":false,"isUC":false,"silkAccelerated":false,"browser":"IE","version":"11.0","os":"Windows 10.0","platform":"Microsoft Windows","geoIp":{},"source":"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"}

res.send(info['platform']);

})

app.listen(3000);
console.log("Listening to Port 3000");

// type "node test.js" in command prompt
// then put this url "http://localhost:3000/" into any browser


By     Created   
The power of the user (%)
72%



The most helpful NODEJS solutions

get user ipget user ipNODEJS

Click to see more ...

  5.3K     1.7K

how to get client netmask using node.js ?how to get client netmask using node.js ?NODEJS

Click to see more ...

  2.8K     557

How to get client machine name and computer name with node.js?How to get client machine name and computer name with node.js?NODEJS

Click to see more ...

  3K     423

how to get client local ip address using node.js ?how to get client local ip address using node.js ?NODEJS

Click to see more ...

  1.3K     311

How to get client ip address using node.jsHow to get client ip address using node.jsNODEJS

Click to see more ...

  1.1K     271

How to combine node.js and jquery ?How to combine node.js and jquery ?NODEJS

Click to see more ...

  1K     247

how to detect tablet, iPad, iPhone, Android and Blackberry using nodejs ?how to detect tablet, iPad, iPhone, Android and Blackberry using nodejs ?NODEJS

Click to see more ...

  1.2K     161

get real user ip address using node.js?get real user ip address using node.js?NODEJS

Click to see more ...

  484     124

how to update a record in mysql using node.js ?how to update a record in mysql using node.js ?NODEJS

Click to see more ...

  428     119

get client region using node.js ?get client region using node.js ?NODEJS

Click to see more ...

  394     118