Skip to content

Instantly share code, notes, and snippets.

View darwinsubramaniam's full-sized avatar

Darwin Subramaniam darwinsubramaniam

View GitHub Profile
@darwinsubramaniam
darwinsubramaniam / sampe.ts
Created July 18, 2020 07:58
NestJs Config , Loading different Env File
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { join } from 'path';
require('dotenv').config();
@Module({
imports: [
ConfigModule.forRoot({
envFilePath: process.env.APP_ENV === 'dev' ?
@darwinsubramaniam
darwinsubramaniam / couchdb.module.ts
Last active July 18, 2020 10:14
sample of the couchdb.module.ts
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import databaseConfig from './database.config';
@Module({
imports: [ConfigModule.forFeature(databaseConfig)],
providers: [],
exports: []
})
export class CouchdbModule { }
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import databaseConfig from './database.config';
@Module({
imports: [ConfigModule.forFeature(databaseConfig)],
providers: [],
exports: []
})
export class CouchdbModule { }
@darwinsubramaniam
darwinsubramaniam / forRootAndForFeature.md
Last active January 31, 2024 08:37
The Explaination of forRoot and ForFeature

ForRoot

This is useful when the registerAs is required across, so it is best to use it in the AppModule

import databaseConfig from './config/database.config';
@Module({
  imports: [
    ConfigModule.forRoot({
      load: [databaseConfig],
 }),
@darwinsubramaniam
darwinsubramaniam / app.module.ts
Created July 18, 2020 10:45
sample appmodule for config
import databaseConfig from './config/database.config';
@Module({
imports: [
ConfigModule.forRoot({
load: [databaseConfig],
}),
],
})
export class AppModule {}
@darwinsubramaniam
darwinsubramaniam / couchdb.service.ts
Last active July 18, 2020 11:08
Sample CouchdbService using registerAs as config
import { Injectable, Inject} from '@nestjs/common';
import databaseConfig from '../database.config';
import { ConfigType } from '@nestjs/config';
@Injectable()
export class CouchdbService{
constructor(
@Inject(databaseConfig.KEY)
@darwinsubramaniam
darwinsubramaniam / couchdb.provider.ts
Created July 18, 2020 11:13
sample provider using config
import { FactoryProvider, Logger } from "@nestjs/common";
import {Configuration, DocumentScope} from 'nano'
import nano = require("nano");
import { ConfigType } from "@nestjs/config";
import databaseConfig from "../database.config";
import { User } from "src/user/user";
export const userDocScopeFactory: FactoryProvider = {
provide: 'UserDocumentScope',
useFactory: async (dbConfig: ConfigType<typeof databaseConfig>):Promise<DocumentScope<User>> => {
@darwinsubramaniam
darwinsubramaniam / main.js
Created August 2, 2020 06:53
simple console log in javascript
console.log('Hi from main.js');
@darwinsubramaniam
darwinsubramaniam / main_typescript.ts
Created August 2, 2020 06:54
simple console in typescript
console.log('Hi from TypeScript');
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */