View log-transport-file.ts
import winston from 'winston'; | |
const logger = winston.createLogger({ | |
level: 'info', | |
format: winston.format.json(), | |
transports: [ | |
new winston.transports.File({ filename: 'stdout.log' }) | |
] | |
}); |
View log-change-level-dynamically.ts
// log setup | |
import winston from 'winston'; | |
const transports = { | |
console: new winston.transports.Console({ level: 'warn' }), | |
}; | |
const logger = winston.createLogger({ | |
transports: [transports.console, transports.file] | |
}); |
View log-exception-trow-function.ts
import logger from '../logSetup'; | |
processLoan(id: number, userId: number) { | |
try { | |
getLoanDeatilsById() | |
} catch(error) { | |
log.error(`Failed to do getLoanDetails with id ${id} hence throwing error`, error); | |
// good example: provide what failed, and how you are handling. | |
// e.g here on fail I am throwing | |
throw error; |
View log-error-function.ts
import logger from '../logSetup'; | |
processLoan(id: number, userId: number) { | |
try { | |
getLoanDeatilsById() | |
} catch(error) { | |
log.error(`Failed to do getLoanDetails with id ${id}, ignoring it and trying to getLoanDetailsByUserId`, error); | |
// good example: provide what failed, and how you are handling. | |
// e.g here on fail I am trying to call other function | |
getLoanDetailsByUserId(); |
View log-stateless-function.ts
import logger from '../logSetup'; | |
createUser() { | |
logger.debug(">>>> Entering createUser"); | |
// ... process | |
logger.debug("Saving user loan {}", userInfoRepository.save(userInfo)) // don't do this | |
return true; |
View log-exception-function.ts
import logger from '../logSetup'; | |
processLoan(...) { | |
logger.debug(">>>> Entering processLoan()"); | |
// ... process | |
logger.debug(`Processing user loan with id ${userService.getUser().getId()}`); | |
// this might throw error, when getUser returns undefined | |
View log-entry-function.ts
import logger from '../logSetup'; | |
getInstallment(month: number, count: number ): number { | |
logger.debug(`>>>> Entering getInstallment(month = ${month}, count= ${count}`); | |
// process | |
const installment: number = 3; | |
log.debug('<<<< Exiting getIntallment()'); | |
return installment; |
View example.js
const GeoJSON = require('./geojson'); | |
const data = [ | |
{ name: 'Location A', category: 'Store', street: 'Market', lat: 39.984, lng: -75.343 }, | |
{ name: 'Location B', category: 'House', street: 'Broad', lat: 39.284, lng: -75.833 }, | |
{ name: 'Location C', category: 'Office', street: 'South', lat: 39.123, lng: -74.534 } | |
]; | |
console.log(GeoJSON.parse(data, {Point: ['lat', 'lng']})); |
View docker-tag
# !/bin/sh | |
docker tag helloworld:latest yourorg/helloworld:$SHA1 | |
docker tag helloworld:latest yourorg/helloworld:$BRANCH_NAME | |
docker tag helloworld:latest yourorg/build_$BUILD_NUM |
View docker-nodeApp-secure
FROM node:8 | |
RUN groupadd -r nodejs && useradd -m -r -g -s /bin/bash nodejs nodejs | |
USER nodejs | |
WORKDIR /home/nodejs/app | |
COPY package.json . | |
RUN npm install --production |
NewerOlder