Just follow this tutorial: https://www.learnwithjason.dev/blog/modern-node-server-typescript-2024
mkdir my-node-app
cd my-node-app/
git init
npm init -y
npm i -D typescript ts-node @types/node
npx tsc --init
{
"engines": {
"node": ">=20.6.0"
},
"name": "my-node-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"dev": "node --env-file=.env --watch -r ts-node/register src/index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jason Lengstorf <jason@learnwithjason.dev>",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.11.17",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
TEST_VALUE=hello
function test(): void {
console.log(process.env.TEST_VALUE);
}
test();
npm run dev