Skip to content

Instantly share code, notes, and snippets.

@Crizzooo
Created February 17, 2017 17:54
Show Gist options
  • Save Crizzooo/7b2c7c2ad93c148a387205fa5604ae22 to your computer and use it in GitHub Desktop.
Save Crizzooo/7b2c7c2ad93c148a387205fa5604ae22 to your computer and use it in GitHub Desktop.
Hi Fullstack Friends!
This gist will walk you through installing snippets I have created to help you work faster and more efficiently in Express!
This gist is specifically for Visual Studio Code Users
--- Installation Instructions ---
1. Go to Code -> Preferences -> User Snippets
2. Select JavaScript
2. Copy all the code below the {COPY CODE BELOW HERE} line
3. Paste it below the final comment
4. Open a .js file and test the snippets using something like aget and then cycling through tab!
VSC uses cson json for writing snippets - you can read more about it here:
https://code.visualstudio.com/Docs/customization/userdefinedsnippets
---
{ COPY CODE BELOW HERE }
---
"Arrow Func with 1 parameter": {
"prefix": "arr",
"body": [
"(${1:param}) => {",
"\t${2}",
"};",
"${3}"
]
},
"router.get Express": {
"prefix": "rget",
"body": [
"router.get('${1:Route}', (req, res, next) => {",
"\t${2}",
"});",
"${3}"
]
},
"router.post Express": {
"prefix": "rpost",
"body": [
"router.post('${1:Route}', (req, res, next) => {",
" ${2}",
"});",
"${3}"
]
},
"router.delete Express": {
"prefix": "rdelete",
"body": [
"router.delete('${1:Route}', (req, res, next) => {",
" ${2}",
"});",
"${3}"
]
},
"router.put Express": {
"prefix": "rput",
"body": [
"router.put('${1:Route}', (req, res, next) => {",
" ${2}",
"});",
"${3}"
]
},
"app.get Express": {
"prefix": "aget",
"body": [
"app.get('${1:Route}', (req, res, next) => {",
" ${2}",
"});",
"${3}"
]
},
"app.post Express": {
"prefix": "apost",
"body": [
"app.post('${1:Route}', (req, res, next) => {",
" ${2}",
"});",
"${3}"
]
},
"app.delete Express": {
"prefix": "adelete",
"body": [
"app.delete('${1:Route}', (req, res, next) => {",
" ${2}",
"});",
"${3}"
]
},
"app.put Express": {
"prefix": "aput",
"body": [
"app.put('${1:Route}', (req, res, next) => {",
" ${2}",
"});",
"${3}"
]
},
"app.use Express": {
"prefix": "appuse",
"body": [
"app.use('${1:Route}', ${2:(req, res, next)} => {",
" ${3}",
"});",
"${4}"
]
},
"bodyParser Express Boilerplate": {
"prefix": "bodyParser Middleware",
"body": [
"//bodyParser middleware",
"app.use(bodyParser.urlencoded({ extended: false }));",
"app.use(bodyParser.json());",
"${1}"
]
},
"default Express Error Handler": {
"prefix": "appErrorHandler",
"body": [
"//Error Handler",
"app.use('${1:Route}', (err, req, res, next) => {",
" res.status(err.status || 500).json(err);${2}",
"});",
"${3}"
]
},
"App Use Static": {
"prefix": "appStatic",
"body": [
"//Static Handling",
"app.use('${1:/}', express.static(path.join(__dirname, '${2}')));",
"${3}"
]
}
} // end bracket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment