• Stars
    star
    629
  • Rank 69,084 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NodeJS user-agent middleware

build status NPM version Git commit with emojis!

Fast Middleware exposing user-agent for NodeJS

express-useragent is a simple NodeJS/ExpressJS user-agent middleware exposing user-agent details to your application and views.

Installation

Installation is done using the Node Package Manager (npm). If you don't have npm installed on your system you can download it from npmjs.org To install express-useragent:

    $ npm install express-useragent --save

Usage overview

Simple Node App

var http = require('http')
  , useragent = require('express-useragent');

var srv = http.createServer(function (req, res) {
  var source = req.headers['user-agent'],
  ua = useragent.parse(source);
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(JSON.stringify(ua));
});

srv.listen(3000);

for TrinteJS

is permanently included

manual setup in project config/middleware.js

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

module.exports = function (app, express) {
    app.use(function () {
        app.use(useragent.express());
    });
};

for ExpressJS

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

app.use(useragent.express());
app.get('/', function(req, res){
    res.send(req.useragent);
});
app.listen(3000);

module provides details such as the following:

{
  "isMobile":false,
  "isDesktop":true,
  "isBot":false,
  .....
  "browser":"Chrome",
  "version":"17.0.963.79",
  "os":"Windows 7",
  "platform":"Microsoft Windows",
  "source":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79..."
}

Accessing the User-Agent

If you are using express or connect, then express-useragent provides an easy way to access the user-agent as:

  • req.useragent from your app server
  • useragent helper accessible from your express views.

Client Side

  • Clone the repo: git clone git://github.com/biggora/express-useragent.git
  • Or Install with Bower: bower install express-useragent.

The client side version of express-useragent available in the lib/ subdirectory.

Include file in your HTML. The minimum required for this plugin are:

    <script type="text/javascript" src="/path/to/express-useragent.js"></script>

Execute the plugin:

    var userAgent = new UserAgent().parse(navigator.userAgent);

Running Tests

Ensure you have nodeunit by running npm install -g nodeunit. Then, run npm test.

npm install
npm test

Run Example Node App

npm run-script http

Run Example Express App

npm run-script express

In the Wild

The following projects use express-useragent.

If you are using express-useragent in a project, app, or module, get on the list below by getting in touch or submitting a pull request with changes to the README.

Author

Aleksejs Gordejevs ([email protected]).

License

(The MIT License)

Copyright (c) 2012-2020 Aleksejs Gordejevs [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Resources

Analytics

Bitdeli Badge

More Repositories

1

caminte

Cross-db ORM for NodeJS
JavaScript
1,091
star
2

bootstrap-ajax-typeahead

Twitter Bootstrap Ajax Typeahead Plugin
JavaScript
173
star
3

device-uuid

Fast browser device uuid generation library. Written in pure JavaScript, no dependencies.
JavaScript
155
star
4

trinte

TrinteJS - Javascrpt MVC Framework for Node.JS
JavaScript
65
star
5

express-mongodb

MongoDB Session Storage for ExpressJS
JavaScript
27
star
6

2co

2CO is the module that will provide nodejs adapters for 2checkout API payment gateway.
JavaScript
20
star
7

express-uploader

Uploading files middleware for NodeJS, Express, TrinteJS, Connect
JavaScript
15
star
8

bootstrap-fancyfile

Browsers do not let you style file inputs. Fancy File Plugin fixes this problem.
JavaScript
11
star
9

connect-caminte

CrossDB session store for Connect and ExpressJS
JavaScript
10
star
10

caminte-generator

RestFul application generator based on CaminteJS ORM
JavaScript
8
star
11

ispconfig_sync_pdns

This script helps you synchronize ISPConfig and the PowerDNS nameserver
PHP
4
star
12

caminte-cli

Command line interface for CaminteJS cross-db ORM
JavaScript
4
star
13

trinte-creator

Script creator for TrinteJS Javascript MVC Framework.
JavaScript
4
star
14

trinte-ejs

Ejs Templates for TrinteJS Framework
JavaScript
3
star
15

ispmanager_proxy

Proxy plugin for ISPManager Lite
PHP
2
star
16

nginx-proxy-dev

HTML
2
star
17

npm-fix-versions

This module provide fixing versions for npm modules in your project
JavaScript
2
star
18

trinte-themes

Bootstrap themes for TrinteJS Framework
CSS
2
star
19

trinte-auth

Login session ensuring middleware for TrinteJS Framework
JavaScript
2
star
20

xml-feed-validator

This is a validator for syndicated feeds. It works with RSS 0.90 - 2.0. It also validates Atom feeds.
JavaScript
2
star
21

expressis

Modified version of the popular web framework Express.
JavaScript
2
star
22

trintejs-netbeans

NetBeans TrinteJS Project Type Module
Java
1
star
23

trinte-subdomain

Subdomain Middleware for TrinteJS & ExpressJS Javascript Frameworks.
JavaScript
1
star
24

gitlab-zone

This is a Dockerfiles to build a container images for gitlab-runner.
Makefile
1
star
25

ag-php-classes

Небольшой PHP класс для работы с изображениями
PHP
1
star