Skip to content

lucaslamar/nodejs-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

NodeJs Snippets

Installation (Not yet possible)

To install an extension you can run Command Pallete using the command Ctrl + Shift + P or Cmd + Shift + P, type Install Extensions and finally give anEnter, done that search by BelleEpoque and you will find the extension es6-nodejs-snippets.

Local Installation

To install an extension locally, you can run the ** Command Pallete ** using Ctrl + Shift + P or Cmd + Shift + P, typing Preferences: Configure User Snippets + New Global Snippets File OR New snippets for local project Create the files and copy the snippets.json AND ts-snippets.json. As shown in the gif below.

Node Component

Supported languages (file extensions)

  • JavaScript (.js)
  • TypeScript (.ts)

Snippets info

Every space inside { } and ( ) means that this is pushed into next line :) $ represent each step after tab.

TypeScript has own components and own snippets. Use search or just type ts before every component snippet.

I.E. tsrcc

Snippets

Basic Methods

Prefix Method
imp→ import moduleName from 'module'
imn→ import 'module'
imd→ import { destructuredModule } from 'module'
ime→ import * as alias from 'module'
ima→ import { originalName as aliasName} from 'module'
exp→ export default moduleName
exd→ export { destructuredModule } from 'module'
exa→ export { originalName as aliasName} from 'module'
enf→ export const functionName = (params) => { }
edf→ export default (params) => { }
fre> array.forEach(currentItem => {})
fof→ for(const item of object) {}
fin→ for(const item in object) {}
anfn→ (params) => {}
nfn→ const add = (params) => {}
dar→ const [first, second] = [1,2]
dob→ const {rename} = fs
sti→ setInterval(() => {});
sto→ setTimeout(() => {});
prom→ return new Promise((resolve, reject) => {});
thenc→ .then((res) => {}).catch((err) => {});
met→ ${1:methodName}(${1:params}) {$3};
met→ methodName = (params) => { }
amet→ async method(params) {}
constructor constructor() {}

Console

Prefix Method
clg→ console.log(object)
clo→ console.log("object", object)
ctm→ console.time("timeId")
cte→ console.timeEnd("timeId")
cas→ console.assert(expression,object)
ccl→ console.clear()
cco→ console.count(label)
cdi→ console.dir
cer→ console.error(object)
cgr→ console.group(label)
cge→ console.groupEnd()
ctr→ console.trace(object)
cwa→ console.warn
cin→ console.info

Sequelize

Prefix Method
cms→ Create a Sequelize model
ccms→ ${1:columns}: Sequelize.${2:STRING}$3,
ccmss→ ${1:column}: Sequelize.STRING$2
ccmsi→ ${1:column}: Sequelize.INTERGER$2
ccmsf→ ${1:column}: Sequelize.FLOAT$2
ccmse→ ${1:column}: Sequelize.ENUM$2

MongoDB

Prefix Method
cfmoo→ Create a Moongoose model

Node.js

Prefix Method
cfne→ Creates a basic express file
tcfne→ Creates a basic express file TS
fcc→ create file of class
fcce→ create a file of class with extends
fccd→ create a file of class destruct
fgr→ Creates routes.js
fgrd→ Creates destruct routes.js
gr→ ${1:routes}.${2:get}('/${3:rotas}', ${4:Rota}Controller.${5:index});
grp→ ${1:routes}.${2:get}('/${3:rotas}/:${4:id}', ${5:Rota}Controller.${6:index});
grpm→ ${1:routes}.${2:get}('/${3:rotas}/:${4:id}', ${5:midware} , ${6:Rota}Controller.${7:index});
grm→ ${1:routes}.${2:get}('/${3:rotas}', ${4:middlewares} ${5:Rota}Controller.${6:index});

Node Components

JavaScript

constructor

constructor() {}

cpro

new Promise((resolve, reject) => {,
 let condition = false;
 if(condition) {
  resolve('data')
   } else {
     reject('error')
  }
 })

cfne

const express = require('express');
  
const ${1:server} = express();,
      
${1:server}.use(express.json());,

const port = 3000;,
      
${1:server}.get('/', (req, res) => json({message: 'Hello World!'}));,
      
${1:server}.listen(port);

fgr

import { Router } from 'express';
   
const ${1:routes} = new Router();
   
export default ${1:routes};

igr

${1:app}.${2:get}('/${3:rotas}', (req, res) => {
 res.json({});
 });

igrm

${1:app}.${2:get}('/${3:rotas}', ${4:middleware} , (req, res) => {
 res.json({});
});

igrp

${1:app}.${2:get}('/${3:rotas}/:${4:id}', (req, res) => {
 res.json({});
});

igrpm

${1:app}.${2:get}('/${3:rotas}/:${5:id}', ${4:middleware}, (req, res) => {
 res.json({});
});

fcc

class $TM_FILENAME_BASE {}
   
export default new $TM_FILENAME_BASE();

fcce

class $TM_FILENAME_BASE extends ${1:Class}  {

 }
   
 export default new $TM_FILENAME_BASE();

cms

import Sequelize, { Model } from 'sequelize';
   
class $TM_FILENAME_BASE extends Model {
 static init(sequelize) {
  super.init(
   {
     $1
   },
   { sequelize }
  );
   
  return this;
  }
 }
   
 export default $TM_FILENAME_BASE;

cfmoo

import mongoose from 'mongoose';
   
const ${1:ExemploSchema} = new mongoose.Schema({});
   
export default mongoose.model(' $TM_FILENAME_BASE',  ${1:ExemploSchema});

icgm

${1:server}.use(req, res, next) => {
   
 next();
});

icgme

${1:app}.use(function(err, req, res, next) {
 console.error(err.stack);
 res.status(500).send('Algo Errado :/!');
});

cgm

function ${1:functionName} (req, res, next) => {
   
 next();
});

ecgm

function ${1:functionName} (req, res, next) => {
   
 next();
});

TypeScript

interface

 interface Interface {
  label: string;
}   

expotInterface

export interface Interface {
  label: value;
}
 

exportInterfaceM

export interface IterfaceMethod {
  IterfaceMethod(paramether): IterfaceMethod<IterfaceMethod>;
}

tigr

app.get('/rotas', (request: Request, response: Response) => {
  response.json({});
});

tigrp

app.get('/rotas/:id', (request: Request, response: Response) => {
  response.json({});
});

tigrpm

app.get('/rotas/:id', [middleware], (request: Request, response: Response) => {
  response.json({});
}); 

tigrm

app.get('/rotas', [middleware] , (request: Request, response: Response) => {
  response.json({});
});
}); 

tfcci

class name implements Class  {}

export default new name();

tfccid

class name implements Class  {}

export { name };

Contribute

  1. Make the fork of the project (https://github.com/lucaslamar/es6-nodejs-snippets/fork)
  2. Create a branch for your modification (git checkout -b feature/fooBar)
  3. Make commit (git commit -m 'feat: estrutura inicial do projeto')
  4. Push (git push origin feature/fooBar)
  5. Create a new Pull Request

license

Distributed under the MIT license. See LICENSE for more information.

Contact

Lucas Lamar - Github - lucass.lamar@gmail.com