I have index.ts
and inside of it I have something like:
const start = () => {...}
Now I have app.ts
that looks like this:
const dotenv = require('dotenv');
dotenv.config();
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const PORT = 4001 || process.env.PORT;
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
// I want to import and call start like this : start()
});
My package.json
looks like this:
{
"name": "...",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node app.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
...
}
}
and tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"allowJs": true,
"checkJs": true,
"outDir": "./built",
"allowSyntheticDefaultImports": true,
"module": "CommonJS"
}
}
The thing is, I can’t use import
directive at all with this setup, so I guess I am doing something wrong.
How to import this function in app.ts
from index.ts
?