Expressjs Snippets
A collection of snippets for Express.js. To initiate, you can either use shorthand methods or type an express method and rest will be autocomplete.
- Supports, es6 syntax.
- Applicable upto Expressjs 4.x.x version.
A collection of Expressjs snippets for Atom
Installation
Go to Settings > Install and then search for expressjs under Packages.
After installing this package, please restart Atom Editor.
Snippets Usage
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.
Common Express Methods:
(es5 versions of methods that use keyword function in place of => functions are suffix by f)
aall|aallfapp.all()adel|adelfapp.delete()adisableapp.disable()adisabledapp.disabled()aenableapp.enable()aenabledapp.enabled()aget|agetfapp.get()apost|apostfapp.apost()aput|aputfapp.put()alisten|alistenfapp.listen() templatelistenapp.listen()arouteapp.route()asetapp.set()auseapp.use()rjsonres.json()rjsonpres.jsonp()rredirectres.redirect()rrenderres.render()rsendres.send()rstatusres.status()rssres.status().send();router()express.Router()rget|rgetfrouter.get()rpost|rpostfrouter.apost()rput|rputfrouter.put()rall|rallfrouter.all()rdel|rdelfrouter.delete()
Initializing app variable
appconst app = express();
Requiring Express
expressconst express = require('express');
Requiring Express-Session
sessionconst session = require('express-session');
Commonly used Middleware
bodyparserjapp.use(bodyParser.json());bodyparserurlapp.use(bodyParser.urlencoded({extended: true}));methodoverrideapp.use(methodOverride('method'));staticfileapp.use(express.static('public'));compressapp.use(compression({level:zlib.Z_DEFAULT_COMPRESSION}));helmetapp.use(helmet());loggerapp.use(logger());
Contribute
Pull requests for more snippets are welcome. If you like to add yours, feel free to contribute.
In lieu of a formal style guide, take care to maintain the existing coding style.
Contributors
Copyright (c) Aman Mittal