I have a server.ts file
require('dotenv').config()
import app from "./app";
// Test
//const port = 4040;
app.listen(port, function() {
console.log('Express server listening on port ' + port);
});
In my app root folder I have an .env file
PORT=4040
My package json file is basic at the minute :
{
"name": "Node TS app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"dev": "ts-node ./lib/server.ts",
"start": "node ./dist/server.js",
"prod": "npm run build && npm start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/express": "^4.11.0",
"body-parser": "^1.18.2",
"dotenv": "^4.0.0",
"express": "^4.16.2"
}
}
I want to get the PORT into the TS file. In VS Code I get an error as port can't be found. Also the npm run dev fails with similar error.
I'm compiling TS to ES5.
Any ideas how I get the value in scope?