├── index.js ├── logo.png ├── .npmignore ├── History.md ├── .gitignore ├── .travis.yml ├── AUTHORS ├── lib └── rid.js ├── test └── rid.test.js ├── Makefile ├── LICENSE.txt ├── package.json └── README.md /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/rid'); -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-modules/rid/HEAD/logo.png -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test/ 2 | coverage.html 3 | Makefile 4 | .travis.yml 5 | logo.png 6 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.0.1 / 2014-01-16 3 | ================== 4 | 5 | * add logo 6 | * first commit 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage.html 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | node_modules 15 | npm-debug.log -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '7' 4 | - '6' 5 | - '4' 6 | - '0.12' 7 | - '0.10' 8 | script: make test-coveralls 9 | before_install: 10 | - 'make install' 11 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Ordered by date of first contribution. 2 | # Auto-generated by 'contributors' on Thu, 16 Jan 2014 02:14:28 GMT. 3 | # https://github.com/xingrz/node-contributors 4 | 5 | fengmk2 (https://github.com/fengmk2) 6 | -------------------------------------------------------------------------------- /lib/rid.js: -------------------------------------------------------------------------------- 1 | /**! 2 | * rid - lib/rid.js 3 | * 4 | * Copyright(c) 2014 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var address = require('address'); 18 | 19 | var IP = address.ip(); 20 | var id = 0; 21 | 22 | function rid() { 23 | return IP + ',' + process.pid + ',' + id++; 24 | } 25 | 26 | module.exports = rid; 27 | -------------------------------------------------------------------------------- /test/rid.test.js: -------------------------------------------------------------------------------- 1 | /**! 2 | * rid - test/rid.test.js 3 | * 4 | * Copyright(c) 2014 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var rid = require('../'); 19 | 20 | describe('rid.test.js', function () { 21 | describe('rid()', function () { 22 | it('should return a string id', function () { 23 | var id = rid(); 24 | id.should.be.a.String; 25 | id.should.match(/^\d+\.\d+\.\d+\.\d+,\d+,\d+$/); 26 | var id2 = rid(); 27 | id2.should.be.a.String; 28 | id2.should.match(/^\d+\.\d+\.\d+\.\d+,\d+,\d+$/); 29 | id2.should.above(id); 30 | rid().should.above(id2); 31 | }); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TESTS = test/*.test.js 2 | REPORTER = spec 3 | TIMEOUT = 1000 4 | MOCHA_OPTS = 5 | 6 | install: 7 | @npm install --registry=http://registry.cnpmjs.org --cache=${HOME}/.npm/.cache/cnpm 8 | 9 | test: install 10 | @NODE_ENV=test ./node_modules/mocha/bin/mocha \ 11 | --reporter $(REPORTER) \ 12 | --timeout $(TIMEOUT) \ 13 | $(MOCHA_OPTS) \ 14 | $(TESTS) 15 | 16 | test-cov: 17 | @$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=travis-cov 18 | 19 | test-cov-html: 20 | @$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov | ./node_modules/.bin/cov 21 | 22 | test-coveralls: test 23 | @echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID) 24 | @-$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js 25 | 26 | test-all: test test-cov 27 | 28 | autod: install 29 | @./node_modules/.bin/autod -w 30 | @$(MAKE) install 31 | 32 | contributors: install 33 | @./node_modules/.bin/contributors -f plain -o AUTHORS 34 | 35 | .PHONY: test 36 | 37 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT License. 2 | 3 | Copyright (C) 2014 fengmk2 and other contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rid", 3 | "version": "0.0.1", 4 | "description": "Request Unique ID, base on current server `ip`, `process.pid` and auto increase id, like `$ip,$pid,$id`", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "make test-all" 8 | }, 9 | "config": { 10 | "blanket": { 11 | "pattern": "rid/lib", 12 | "data-cover-flags": { 13 | "debug": false 14 | } 15 | }, 16 | "travis-cov": { 17 | "threshold": 100 18 | } 19 | }, 20 | "dependencies": { 21 | "address": "0.0.3" 22 | }, 23 | "devDependencies": { 24 | "autod": "*", 25 | "blanket": "*", 26 | "contributors": "*", 27 | "cov": "*", 28 | "coveralls": "*", 29 | "mocha": "*", 30 | "mocha-lcov-reporter": "*", 31 | "should": "2.1.1", 32 | "travis-cov": "*" 33 | }, 34 | "homepage": "https://github.com/fengmk2/rid", 35 | "repository": { 36 | "type": "git", 37 | "url": "git://github.com/fengmk2/rid.git", 38 | "web": "https://github.com/fengmk2/rid" 39 | }, 40 | "bugs": { 41 | "url": "https://github.com/fengmk2/rid/issues", 42 | "email": "fengmk2@gmail.com" 43 | }, 44 | "keywords": [ 45 | "rid" 46 | ], 47 | "engines": { 48 | "node": ">= 0.10.0" 49 | }, 50 | "author": "fengmk2 (http://fengmk2.github.com)", 51 | "license": "MIT" 52 | } 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | rid 2 | ======= 3 | 4 | [![Build Status](https://secure.travis-ci.org/fengmk2/rid.png)](http://travis-ci.org/fengmk2/rid) [![Coverage Status](https://coveralls.io/repos/fengmk2/rid/badge.png)](https://coveralls.io/r/fengmk2/rid) [![Dependency Status](https://gemnasium.com/fengmk2/rid.png)](https://gemnasium.com/fengmk2/rid) 5 | 6 | [![NPM](https://nodei.co/npm/rid.png?downloads=true&stars=true)](https://nodei.co/npm/rid/) 7 | 8 | ![logo](https://raw.github.com/fengmk2/rid/master/logo.png) 9 | 10 | Request Unique ID, base on current server `ip`, `process.pid` and auto increase id, like `$ip,$pid,$id` 11 | 12 | So your client just tell you the `Request ID`, then you `grep` the ID, 13 | you can find out what's happen on this request. 14 | 15 | ## Install 16 | 17 | ```bash 18 | $ npm install rid 19 | ``` 20 | 21 | ## Usage 22 | 23 | ```js 24 | var rid = require('rid'); 25 | 26 | console.log(rid()); // '10.0.0.1,68732,0' 27 | console.log(rid()); // '10.0.0.1,68732,1' 28 | 29 | // another process 30 | var rid = require('rid'); 31 | 32 | console.log(rid()); // '10.0.0.1,68733,0' 33 | console.log(rid()); // '10.0.0.1,68733,1' 34 | 35 | // another node server 36 | var rid = require('rid'); 37 | 38 | console.log(rid()); // '10.0.0.2,5017,0' 39 | console.log(rid()); // '10.0.0.2,5017,1' 40 | ``` 41 | 42 | ## License 43 | 44 | (The MIT License) 45 | 46 | Copyright (c) 2014 fengmk2 <fengmk2@gmail.com> and other contributors 47 | 48 | Permission is hereby granted, free of charge, to any person obtaining 49 | a copy of this software and associated documentation files (the 50 | 'Software'), to deal in the Software without restriction, including 51 | without limitation the rights to use, copy, modify, merge, publish, 52 | distribute, sublicense, and/or sell copies of the Software, and to 53 | permit persons to whom the Software is furnished to do so, subject to 54 | the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be 57 | included in all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 60 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 61 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 62 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 63 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 64 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 65 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 66 | --------------------------------------------------------------------------------