Nodejs Snippets for Atom
A collection of Nodejs, JavaScript snippets.
This package also support some of the ES6 syntax half-heartedly.
Go to Settings > Install & then search for atom-nodejs-snippets under Packages. After installation, restart Atom.
These snippets are for daily use to avoid writing as much as it could the boilerplate code. If you like, to add yours, feel free to contribute.
To use, please press tab after shortkeys expressed as following.
Nodejs Commonly used entities:
- reqrequire
- memodule.exports
- exexports
- cbcallback()
path Module
- pjoinpath.join()
- pdirpath.dirname()
- prespath.resolve()
- pbasepath.basename()
- pextpath.extname()
fs Module
- fsreadfs.readFile()
- fsreadstreamfs.createReadStream()
- fswritefs.writeFile()
event Module
- onevent handler | emitter.on('event',() => {})
stream Module
- rstreamreadable stream
- wstreamwritable stream
- pipers.pipe(ws);
Process & Global Variables
- process.env
- process.pid
- process.cwd
- process.stdin
- process.stdout
- process.stderr
- process.version
- process.argv
- process.exit
- process.kill
- process.uptime
- dirndirname
boilerplate code for importing core modules
For ES6:
Eg: const util = require('util');
- util
- http
- fs
- path
- zlib
- stream
- qstring
- assert
- url
- string_decoder
Consoles Shorthand
- clogconsole.log()
- cwconsole.warn()
- cdconsole.dir()
- ciconsole.info()
- ceconsole.error()
- cgconsole.group()
- cgeconsole.groupEnd()
assert Module
- assert.equal
- assert.notEqual
- assert.deepEqual
- assert.ok
- assert.ifError
Promise
- pnew Promise(function(resolve, reject) {});
- pthenpromise.then(function (){});
- pcatchpromise.catch(function (err) {});
timer functions
- sisetInterval()
- stsetTimeout()
- simsetImmediate()
BDD Testing
- descdescribe
- itit in synchronous
- itasyncit in asynchronous
- itpendingit pending
- befbefore()
- aftafter()
- befebeforeEach()
- afteafterEach()
BDD Chai expect Library
- expectconst expect = chai.expect;
- expecteexpect equal
- expectdeexpect deep equal
- expectneexpect not equal
- expectndeexpect not deep equal
Common JS Syntax
- kvkey:value pair (object)
- fnmmethod (object)
- fnanonymous function
- fnoanonymous function without parameter
- fnnnamed function
- fnefunction expression
- iifeimmediately invoked function expression
- rreturn
- rtreturn true
- rfreturn false
- rpreturn promise
- alalert
- us;strict mode
ES6 Syntax
- impimport X from module
- ararrow function with parameters
- aroarrow function without parameters
- arnnamed arrow function
- cb6Nodejs callback in ES6
- methMethod (object)
- getgetter
- setsetter
process.nextTick()
- nexttick
JSON
- jparseJSON.parse()
- jstrJSON.stringify()
- Add more ES6 snippets
- Convert BDD & BDD Chai Library snippets to ES6
Pull requests for more snippets are welcome.
MIT Copyright (c) 2016 Aman Mittal