티스토리 뷰
다른 작업을 진행하다가 정말로 오랜만에 다시 Node.js 관련 오픈 소스 분석 작업을 하는데 참조하고 있는 패키지들이 많기도 하다. 아는 것보다는 모르는 것이 더 많아서 뭐가 뭔지 하나도 모르겠다.
앞으로 작업을 하면서 좀 더 다양한 패키지들을 자세하게 알아야 하지만, 당장은 제목과 기능이라도 알아야 이해를 할 수 있을 듯 하다. ㅠㅠ
Packages for NodeJS
bluebird
Full featured promise library with unmatched performance
Examples
설치
npm install bluebird
활용법
var Promise = require("bluebird");
References
bunyan
Simple and fast JSON Logging Module for node.js services
Examples
설치
$ npm install bunyan
활용법
var bunyan = require('bunyan'); var log = bunyan.createLogger({name: "myapp"}); log.info("hi");
References
camelcase
Convert a dash/dot/underscore/space separated string to camelCase: foo-bar -> fooBar
Examples
설치
$ npm install --save camelcase
활용법
const camelCase = require('camelcase'); camelCase('foo-bar'); //=> 'fooBar' camelCase('foo_bar'); //=> 'fooBar' camelCase('Foo-Bar'); //=> 'fooBar' camelCase('--foo.bar'); //=> 'fooBar' camelCase('__foo__bar__'); //=> 'fooBar' camelCase('foo bar'); //=> 'fooBar' camelCase('foo', 'bar'); //=> 'fooBar' camelCase('__foo__', '--bar'); //=> 'fooBar' console.log(process.argv[3]); //=> '--foo-bar' camelCase(process.argv[3]); //=> 'fooBar'
References
chai
BDD (Behavior-Driven Development) / TDD (Test-Driven Development) Assersion Library for Node
Examples
설치
$ npm install bunyan
활용법
// Should chai.should(); foo.should.be.a('string'); foo.should.equal('bar'); foo.should.have.lengthOf(3); tea.should.have.property('flavors').with.lengthOf(3); // Expect var expect = chai.expect; expect(foo).to.be.a('string'); expect(foo).to.equal('bar'); expect(foo).to.have.lengthOf(3); expect(tea).to.have.property('flavors').with.lengthOf(3); // Assert var assert = chai.assert; assert.typeOf(foo, 'string'); assert.equal(foo, 'bar'); assert.lengthOf(foo, 3) assert.property(tea, 'flavors'); assert.lengthOf(tea.flavors, 3);
References
chalk
Terminal String Styling done right
Examples
설치
$ npm install chalk
활용법
const chalk = require('chalk'); console.log(chalk.blue('Hello world!'));
References
chokidar
A neat wrapper around node.js fs.watch / fs.watchFile / fsevents.
Examples
설치
$ npm install chokidar --save
활용법
var chokidar = require('chokidar'); // One-liner for current directory, ignores .dotfiles chokidar.watch('.', {ignored: /(^|[\/\\])\../}).on('all', (event, path) => { console.log(event, path); }); // Example of a more typical implementation structure: // Initialize watcher. var watcher = chokidar.watch('file, dir, glob, or array', { ignored: /(^|[\/\\])\../, persistent: true }); // Something to use when events are received. var log = console.log.bind(console); // Add event listeners. watcher .on('add', path => log(`File ${path} has been added`)) .on('change', path => log(`File ${path} has been changed`)) .on('unlink', path => log(`File ${path} has been removed`)); // More possible events. watcher .on('addDir', path => log(`Directory ${path} has been added`)) .on('unlinkDir', path => log(`Directory ${path} has been removed`)) .on('error', error => log(`Watcher error: ${error}`)) .on('ready', () => log('Initial scan complete. Ready for changes')) .on('raw', (event, path, details) => { log('Raw event info:', event, path, details); }); // 'add', 'addDir' and 'change' events also receive stat() results as second // argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats watcher.on('change', (path, stats) => { if (stats) console.log(`File ${path} changed size to ${stats.size}`); }); // Watch new files. watcher.add('new-file'); watcher.add(['new-file-2', 'new-file-3', '**/other-file*']); // Get list of actual paths being watched on the filesystem var watchedPaths = watcher.getWatched(); // Un-watch some files. watcher.unwatch('new-file*'); // Stop watching. watcher.close(); // Full list of options. See below for descriptions. (do not use this example) chokidar.watch('file', { persistent: true, ignored: '*.txt', ignoreInitial: false, followSymlinks: true, cwd: '.', usePolling: true, interval: 100, binaryInterval: 300, alwaysStat: false, depth: 99, awaitWriteFinish: { stabilityThreshold: 2000, pollInterval: 100 }, ignorePermissionErrors: false, atomic: true // or a custom 'atomicity delay', in milliseconds (default 100) });
References
escape-string-regexp
Escape RegExp Special Characters
Examples
설치
$ npm install --save escape-string-regexp
활용법
const escapeStringRegexp = require('escape-string-regexp'); const escapedString = escapeStringRegexp('how much $ for a unicorn?'); //=> 'how much \$ for a unicorn\?' new RegExp(escapedString);
References
eslint
Pluggable Linting utility for JavaScript and JSX
Examples
설치
$ npm install eslint
활용법
Rule 정의 파일 구성 $ npm run eslint .
References
graceful-fs
drop-in replacement for the fs module, making various improvements.
Examples
설치
$ npm install graceful-fs
활용법
// use just like fs var fs = require('graceful-fs') // now go and do stuff with it... fs.readFileSync('some-file-or-whatever') // // Global Patching // // Make sure to read the caveat below. var realFs = require('fs') var gracefulFs = require('graceful-fs') gracefulFs.gracefulify(realFs)
References
istanbul
JS Code Coverage tool written in JS
Examples
설치
$ npm install -g istanbul
활용법
$ istanbul cover test.js
References
jscs
Javascript Code Style Checker
Examples
설치
$ npm install jscs
-
활용법
$ jscs file.js --preset=airbnb
References
minimist
guts of optimist's argument parser without all the fanciful decoration
Examples
설치
$ npm install minimist
활용법
var argv = require('minimist')(process.argv.slice(2)); console.dir(argv);
References
mocha
Fun, Simple, Flexible Javascript Test Framework
Examples
설치
$ npm install mocha
활용법
Assert 파일 작성 $ mocha test/index.js
References
nyc
Istanbul command line interface
Examples
설치
$ npm i nyc --save-dev
활용법
package.json script 설정
{ "script": { "test": "nyc tap ./test/*.js" } }
실행
$ nyc npm test $ nyc --reporter=lcov --reporter=text-lcov npm test
References
require-dir
Node.js 지원을 위해 지정한 디렉터리 단위로 존재하는 파일들을 일괄 require() 처리
Examples
설치
$ npm install require-dir
활용법
var requireDir = require('require-dir'); var dir = requireDir('./path/to/dir'); var dir = requireDir('./path/to/dir', {recurse: true});
References
rewire
Easy monkey-patching for node.js unit tests
Examples
설치
$ npm install rewire
활용법
자세한 활용법은 아래 사이트 설명 참조
References
shelljs, shelljs/shx
shelljs: Portable Unix shell commands for Node.js shelljs/shx: Portable Shell Commands for Node.js
Examples
설치
$ npm install shelljs $ npm install shelljs/shx # for command line
활용법 (shelljs)
var shell = require('shelljs'); if (!shell.which('git')) { shell.echo('Sorry, this script requires git'); shell.exit(1); } // Copy files to release dir shell.rm('-rf', 'out/Release'); shell.cp('-R', 'stuff/', 'out/Release'); // Replace macros in each .js file shell.cd('lib'); shell.ls('*.js').forEach(function (file) { shell.sed('-i', 'BUILD_VERSION', 'v0.1.2', file); shell.sed('-i', /^.*REMOVE_THIS_LINE.*$/, '', file); shell.sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, shell.cat('macro.js'), file); }); shell.cd('..'); // Run external tool synchronously if (shell.exec('git commit -am "Auto-commit"').code !== 0) { shell.echo('Error: Git commit failed'); shell.exit(1); }
활용법 (shelljs/shx)
# used in command line using shx $ shx mkdir -p foo $ shx touch foo/bar.txt $ shx rm -rf foo
References
sinon
Standalone test spies, stubs and mocks for Javascript. work with any unit testing framework.
Examples
설치
$ npm install sinon
활용법
자세한 활용법은 아래 사이트 설명 참조
References
standard
Javascript 표준 스타일 가이드 with Linter & Automatic code fixer
Examples
설치
$ npm install standard --save-dev
활용법
$ standard Error: Use JavaScript Standard Style lib/torrent.js:950:11: Expected '===' and instead saw '=='. $ standard "src/util/**/*.js" "test/**/*.js"
References
tildify
Convert an absolute path to the tilde path: /Users/sindresorhus/dev to ~/dev
Examples
설치
$ npm install --save tildify
활용법
const tildify = require('tildify'); tildify('/Users/sindresorhus/dev'); //=> '~/dev'
References
yargs
Yargs helps you build interactive command line tools by parsing arguments and generating an elegant user interface
Examples
설치
$ npm install yargs
활용법
#!/usr/bin/env node require('yargs') .usage('$0 <cmd> [args]') .command('hello [name]', 'welcome ter yargs!', { name: { default: 'default name' } }, function (argv) { console.log('hello', argv.name, 'welcome to yargs!') }) .help() .argv 자세한 활용법은 아래 사이트 설명 참조
References
Written by Morris (ccambo@gmail.com - MSFL)
'개발 > 기타언어' 카테고리의 다른 글
[Golang] 의존성 없이 웹으로 서비스할 정적 파일들을 Golang 바이너리에 추가하기 (0) | 2020.12.18 |
---|---|
[Markdown] 특수문자들을 정리해 보자! (0) | 2017.04.05 |
[NODE] NPM Install 처리시에 MSBuild 관련 오류 발생하는 경우 (0) | 2017.01.11 |
[Python] Eclipse + PyDev 개발환경 구성하기 (Hello World!) (2) | 2015.02.09 |
- Total
- Today
- Yesterday
- NFS
- ssh
- Cluster
- SolrCloud
- kudo-cli
- custom resource
- Galera Cluster
- Packages
- operator framework
- dynamic nfs client provisioner
- Node
- collection
- leader
- provisioner
- docker
- Replica
- Kudo
- galera
- GIT
- opencensus
- terrminating
- operator
- CentOS
- macos
- zookeeper
- 쿠버네티스
- KUBECTL
- k8s
- CentOS 8
- Kubernetes
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |