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:
reqrequirememodule.exportsexexportscbcallback()
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 streamwstreamwritable streampipers.pipe(ws);
Process & Global Variables
process.envprocess.pidprocess.cwdprocess.stdinprocess.stdoutprocess.stderrprocess.versionprocess.argvprocess.exitprocess.killprocess.uptimedirndirname
boilerplate code for importing core modules
For ES6:
Eg: const util = require('util');
utilhttpfspathzlibstreamqstringasserturlstring_decoder
Consoles Shorthand
clogconsole.log()cwconsole.warn()cdconsole.dir()ciconsole.info()ceconsole.error()cgconsole.group()cgeconsole.groupEnd()
assert Module
assert.equalassert.notEqualassert.deepEqualassert.okassert.ifError
Promise
pnew Promise(function(resolve, reject) {});pthenpromise.then(function (){});pcatchpromise.catch(function (err) {});
timer functions
sisetInterval()stsetTimeout()simsetImmediate()
BDD Testing
descdescribeitit in synchronousitasyncit in asynchronousitpendingit pendingbefbefore()aftafter()befebeforeEach()afteafterEach()
BDD Chai expect Library
expectconst expect = chai.expect;expecteexpect equalexpectdeexpect deep equalexpectneexpect not equalexpectndeexpect not deep equal
Common JS Syntax
kvkey:value pair (object)fnmmethod (object)fnanonymous functionfnoanonymous function without parameterfnnnamed functionfnefunction expressioniifeimmediately invoked function expressionrreturnrtreturn truerfreturn falserpreturn promisealalertus;strict mode
ES6 Syntax
impimport X from moduleararrow function with parametersaroarrow function without parametersarnnamed arrow functioncb6Nodejs callback in ES6methMethod (object)getgettersetsetter
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