{"id":17998416,"url":"https://github.com/primaryobjects/usersonline","last_synced_at":"2025-04-04T06:42:13.907Z","repository":{"id":8196373,"uuid":"9626823","full_name":"primaryobjects/usersonline","owner":"primaryobjects","description":"List the most recent 100 users visiting your site in node.js Express: Date, Time, IP Address, User Agent, Landing Page, Referring Url.","archived":false,"fork":false,"pushed_at":"2016-01-14T16:41:01.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T22:50:29.013Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/primaryobjects.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-23T15:45:36.000Z","updated_at":"2024-02-20T02:58:07.000Z","dependencies_parsed_at":"2022-07-21T14:30:06.928Z","dependency_job_id":null,"html_url":"https://github.com/primaryobjects/usersonline","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Fusersonline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Fusersonline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Fusersonline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Fusersonline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/primaryobjects","download_url":"https://codeload.github.com/primaryobjects/usersonline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135123,"owners_count":20889420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-29T21:25:14.592Z","updated_at":"2025-04-04T06:42:13.887Z","avatar_url":"https://github.com/primaryobjects.png","language":"JavaScript","readme":"﻿UsersOnline\n--------\n\nList the most recent 100 users visiting your site and display the date, time, IP address, user agent, landing page, referring url.\n\nThis module tracks each new user that first visits your site, by activating upon the start of a new session. When a new session is activated, the user's referring url information is added to a queue. You can output the queue in your view, such as on an administrator page, to get a quick view of the users accessing your site.\n\nFor example:\n```\n1. 4/23/2013 11:42:07 AM - 127.0.0.1\nMozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31\nlanding: http://www.primaryobjects.com/users\nreferer: http://www.google.com/search?q=software+design\u0026aq=0\u0026oq=software+design\n```\n\n## Usage\n\nInstall the node.js module.\n```bash\n$ npm install usersonline\n```\n\n## app.js\n```\nvar session = require('express-session'),\n    usersonline = require('usersonline');\n\nvar app = express();\n\napp.use(session({ secret: 'secret-session-key', resave: false, saveUninitialized: false })); // Enable session.\napp.use(usersonline.logger); // Enable usersonline.\n\napp.get('/users', function(req, res, next) {\n    res.json(usersonline.visitorList);\n});\n```\n\nNote, if you are using express.static() for static files, the line `app.use(usersonline.logger)` must come before it.\n\nTo display the users online in a static HTML page, simply make a request to /users and display the resulting JSON, as follows:\n\n## users.html\n\n```\n\u003chtml\u003e\n\u003chead\u003e\n\u003cscript src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nfunction getUsers() {\n    $.get('/users', function(data) {\n        for (var i in data) {\n            var visitor = data[i];\n            var status = $('#status');\n\n            status.append((parseInt(i) + 1) + '. ' + visitor.date + ' - ' + visitor.ip + '\u003cbr\u003e');\n            status.append(visitor.userAgent + '\u003cbr\u003e');\n            status.append('landing: ');\n            status.append(\"\u003ca href='\" + visitor.url + \"', target='_blank'\u003e\" + visitor.url + \"\u003c/a\u003e\u003cbr\u003e\");\n            if (visitor.referer != undefined) {\n                status.append('referer: ');\n                status.append(\"\u003ca href='\" + visitor.referer + \"', target='_blank'\u003e\" + visitor.referer + \"\u003c/a\u003e\u003cbr\u003e\");\n            }\n            status.append('\u003cbr\u003e');\n        }\n    });\n}\n$(document).ready(function() { getUsers(); });\n\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch2\u003eUsers Online\u003c/h2\u003e\n    \u003cdiv id=\"status\"\u003e\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nIf you are using express routing, you can display the UsersOnline list in your view route, as follows:\n\n## index.js\n```\nvar usersonline = require('usersonline');\n\nexports.index = function(req, res) {\n  res.render('index', { visitorList: usersonline.visitorList });\n};\n```\n\n## index.jade\n```\neach visitor, i in visitorList\n\tp\n\t\tdiv\n\t\t\t| #{i + 1}. #{visitor.date} - #{visitor.ip}\n\t\tdiv\n\t\t\t| #{visitor.userAgent}\n\t\tdiv\n\t\t\t| landing:\n\t\t\ta(href='#{visitor.url}', target='_blank') #{visitor.url}\n\t\tdiv\n\t\t\tif (visitor.referer != undefined)\n\t\t\t\t| referer:\n\t\t\t\ta(href='#{visitor.referer}', target='_blank') #{visitor.referer}\t\t\t\t\t\t\n```\n\n## index.ejs\n```\n\u003c%\nvar content = '';\n\nfor (var i=0; i\u003cvisitorList.length; i++) {\n\tcontent += '\u003cp\u003e\u003cb\u003e' + (i + 1) + '.\u003c/b\u003e ' + visitorList[i].date + ' - ' + visitorList[i].ip + '\u003cbr/\u003e';\n\tcontent += visitorList[i].userAgent + '\u003cbr/\u003elanding: \u003ca href=\"' + visitorList[i].url + '\" target=\"_blank\"\u003ehttp://www.primaryobjects.com' + visitorList[i].url + '\u003c/a\u003e';\n\tcontent += (visitorList[i].referer == undefined ? '' : '\u003cbr/\u003ereferer: \u003ca href=\"' + visitorList[i].referer + '\" target=\"_blank\"\u003e' + visitorList[i].referer + '\u003c/a\u003e');\n\tcontent += '\u003c/p\u003e';\n\t\n\tmyTemplateBlock = content;\n}\n%\u003e\n```\n\n## Source\n\nhttps://github.com/primaryobjects/usersonline\n\n## Author\n\nKory Becker\nhttp://www.primaryobjects.com\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimaryobjects%2Fusersonline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprimaryobjects%2Fusersonline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimaryobjects%2Fusersonline/lists"}