Fix: Setup path alias for Typesctipt/ Nest/js

Shivam Gupta
May 31, 2023

With Typescript/Nest js if we want to set path alias like dont want to traverse to whole path example —

we have a file — configs/env.config.ts

how to import that config:

import { CONFIG } from ‘configs/env.config.ts’

but we can also set path alias to short path to folder or to file by —

  1. open tsconfig.json and inside compilerOptions add a key paths —
defining path alias for a fil and folder

2. And also update in tsconfig.json > compilerOptions

“moduleResolution”: “node”,

3. npm i tsconfig-paths

4. Now u can use path alias likke —

import CONFIGS from ‘@env’;

Is this article helpful ? Please clap and write in comment section

--

--

Shivam Gupta

Full Stack Engineer (Web/App) working on different JS Technologies & frameworks— Angular, Node, Typescript, Ionic, Firebase, AWS, ElK...Love to write cool stuff