Skip to content

A piece of code that allows for determing whether the client of a node.js http server is using a mobile or not.

License

Notifications You must be signed in to change notification settings

felix-khlmnn/mobile-device-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mobile-device-detection

This simple module allows you to find out whether a client of an http server you run is using a mobile device or not. Also, the module does not require any dependencies, as it only uses the preinstalled http module.

Functionality

The function "checkIfMobile" returns a boolean. The value is "true", if the client is using a mobile device. All that needs to be passed into the function is the request of the client. Below you will find a demonstration of the module.

Usage

const http = require("http");
const mdd = require("mobile-device-detection");

http.createServer((req, res) => {
    console.log(mdd.checkIfMobile(req));
    res.end();
}).listen(8080);

This will result in two possible logs in the console:

true

This means that the requesting client is using a mobile device.

false

This means that the requesting client is not using a mobile device.

Credit

This is not my code! As I stumbled upon the issue of mobile device detection myself, I found a snippet of code in this DZone article and decided to condense it down into an easy to find module.

Contact

If you run in any problems, feel free to write me an email or just add me on Discord (dixi0505#0135). I hope that you'll find this module useful.

About

A piece of code that allows for determing whether the client of a node.js http server is using a mobile or not.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published