Atom
Nodejs Snippets forA collection of Nodejs, JavaScript snippets.
This package also support some of the ES6 syntax half-heartedly.
Install
Go to Settings > Install
& then search for atom-nodejs-snippets
under Packages. After installation, restart Atom.
Snippets
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:
req
requireme
module.exportsex
exportscb
callback()
path Module
pjoin
path.join()pdir
path.dirname()pres
path.resolve()pbase
path.basename()pext
path.extname()
fs Module
fsread
fs.readFile()fsreadstream
fs.createReadStream()fswrite
fs.writeFile()
event Module
on
event handler | emitter.on('event',() => {})
stream Module
rstream
readable streamwstream
writable streampipe
rs.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
dirn
dirname
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
clog
console.log()cw
console.warn()cd
console.dir()ci
console.info()ce
console.error()cg
console.group()cge
console.groupEnd()
assert Module
assert.equal
assert.notEqual
assert.deepEqual
assert.ok
assert.ifError
Promise
p
new Promise(function(resolve, reject) {});pthen
promise.then(function (){});pcatch
promise.catch(function (err) {});
timer functions
si
setInterval()st
setTimeout()sim
setImmediate()
BDD Testing
desc
describeit
it in synchronousitasync
it in asynchronousitpending
it pendingbef
before()aft
after()befe
beforeEach()afte
afterEach()
BDD Chai expect Library
expect
const expect = chai.expect;expecte
expect equalexpectde
expect deep equalexpectne
expect not equalexpectnde
expect not deep equal
Common JS Syntax
kv
key:value pair (object)fnm
method (object)fn
anonymous functionfno
anonymous function without parameterfnn
named functionfne
function expressioniife
immediately invoked function expressionr
returnrt
return truerf
return falserp
return promiseal
alertus;
strict mode
ES6 Syntax
imp
import X from modulear
arrow function with parametersaro
arrow function without parametersarn
named arrow functioncb6
Nodejs callback in ES6meth
Method (object)get
getterset
setter
process.nextTick()
nexttick
JSON
jparse
JSON.parse()jstr
JSON.stringify()
TODO
Contribute
Pull requests for more snippets are welcome.
License
MIT Copyright (c) 2016 Aman Mittal