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

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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.