-
Notifications
You must be signed in to change notification settings - Fork 0
/
express.code-snippets
72 lines (72 loc) · 1.64 KB
/
express.code-snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
"Express Controller Action": {
"prefix": "!expract",
"scope": "javascript",
"body": [
"module.exports.$1 = async (req, res, next) => {",
"\ttry {",
"\t\t$2",
"\t} catch (error) {",
"\t\tnext(error);",
"\t}",
"};",
""
]
},
"Express Router": {
"prefix": "!exprrout",
"scope": "javascript",
"body": [
"const { Router } = require('express');",
"const controller = require('./controller');",
"",
"const $1Router = Router();",
"",
"$2",
"",
"module.exports = $1Router;",
""
]
},
"Express Dto Model": {
"prefix": "!exprdto",
"scope": "javascript",
"body": [
"class ${TM_FILENAME_BASE/(^[a-zA-Z])/${1:/upcase}/} {",
"\tconstructor(data) {",
"\t\t$1",
"\t}",
"}",
"",
"module.exports = ${TM_FILENAME_BASE/(^[a-zA-Z])/${1:/upcase}/};",
""
]
},
"Express Cron Job": {
"prefix": "!exprcron",
"scope": "javascript",
"body": [
"const { CronJob } = require('cron');",
"",
"/**",
" * Don't use the arrow function",
" * https://www.npmjs.com/package/cron#gotchas",
" */",
"async function ${TM_FILENAME_BASE}Cron() {",
"\ttry {",
"\t\t$1",
"\t} catch (error) {",
"\t\tconsole.error('[${TM_FILENAME_BASE}Cron]', error.message); // eslint-disable-line no-console",
"\t\treturn Promise.resolve();",
"\t}",
"}",
"",
"module.exports = new CronJob({",
"\tcronTime: $2,",
"\tonTick: ${TM_FILENAME_BASE}Cron,",
"\trunOnInit: $3,",
"});",
""
]
}
}