'How to import config file from folder in nestjs

I am creating nestjs project in which I have config folder which has config files based on environments like local, staging, or production. I want to import this file into another file but when I am trying to do so its showing error:

Below is my files:

config/config-local.t2

export const env = 'local';
export const databases = {
 mongodb_url: 'mongodb://localhost/truckload',
 es_url: 'http://localhost:9200'
};
export const logConfig = {
 path : '/Users/services/example.log',
};

Now I want to import mongodb_url in a different file for that I am importing something like this

import { databases } from '../config/config-local.t2';

But it's showing an error below importing statement. How can I import database property from the config file?



Solution 1:[1]

I don't know why are you using the .t2 format for a config file, however, for such importing you must change the config file format to .ts to be a valid TypeScript format. Then, the import statement will be like this:

import { databases } from '../config/config-local';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hadi Samadzad