Absoulate import in node express typescript project configrations.

If you want to enabled typescript express project for absoulate import and want remove ../.. from entire project this guide for you:

at first you need to configure tsconfig.json file where you need to configure absoulate path. You can check below file…


This content originally appeared on DEV Community and was authored by Md. Khalid Hossen

If you want to enabled typescript express project for absoulate import and want remove ../.. from entire project this guide for you:

at first you need to configure tsconfig.json file where you need to configure absoulate path. You can check below file:


{
    "compilerOptions": {
      "target": "ES2020",
      "module": "commonjs",
      "strict": true,
      "esModuleInterop": true,
      "skipLibCheck": true,
      "forceConsistentCasingInFileNames": true,
      "outDir": "./dist",
      "rootDir": "./src",
      "baseUrl": ".",
      "paths": {
        "*": ["node_modules/*"],
        "@/*": ["src/*"], 
      }
    },
    "include": ["./env.d.ts", "src/**/*.ts"],
    "exclude": ["node_modules"]
  }

Note:
here i have used path as @/* and src is my base url

Then you need to add another library for configure this, tsconfig-paths it and chage your running script then everything will be fine.

script should be like this:

"scripts": {
    "dev": "nodemon --watch src --exec ts-node --require tsconfig-paths/register --transpile-only src/main.ts",
  },


This content originally appeared on DEV Community and was authored by Md. Khalid Hossen


Print Share Comment Cite Upload Translate Updates
APA

Md. Khalid Hossen | Sciencx (2024-11-03T15:06:08+00:00) Absoulate import in node express typescript project configrations.. Retrieved from https://www.scien.cx/2024/11/03/absoulate-import-in-node-express-typescript-project-configrations/

MLA
" » Absoulate import in node express typescript project configrations.." Md. Khalid Hossen | Sciencx - Sunday November 3, 2024, https://www.scien.cx/2024/11/03/absoulate-import-in-node-express-typescript-project-configrations/
HARVARD
Md. Khalid Hossen | Sciencx Sunday November 3, 2024 » Absoulate import in node express typescript project configrations.., viewed ,<https://www.scien.cx/2024/11/03/absoulate-import-in-node-express-typescript-project-configrations/>
VANCOUVER
Md. Khalid Hossen | Sciencx - » Absoulate import in node express typescript project configrations.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/03/absoulate-import-in-node-express-typescript-project-configrations/
CHICAGO
" » Absoulate import in node express typescript project configrations.." Md. Khalid Hossen | Sciencx - Accessed . https://www.scien.cx/2024/11/03/absoulate-import-in-node-express-typescript-project-configrations/
IEEE
" » Absoulate import in node express typescript project configrations.." Md. Khalid Hossen | Sciencx [Online]. Available: https://www.scien.cx/2024/11/03/absoulate-import-in-node-express-typescript-project-configrations/. [Accessed: ]
rf:citation
» Absoulate import in node express typescript project configrations. | Md. Khalid Hossen | Sciencx | https://www.scien.cx/2024/11/03/absoulate-import-in-node-express-typescript-project-configrations/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.