alex-009
alex-009β€’15mo ago

Best way for application config in deno/ts?

Hi. I'm alex and quite new to deno/typescript. Thank you for the quite big documenation it is a quite good starting point πŸ₯° I have created a upload module for caddy server ( https://github.com/git001/caddyv2-upload/ ) and try to "port/migrate/redevelop" this in typescript. Sorry for the long first post, but I'm not sure if this is the right forum, if not please redirect me to the right one πŸ™‚ . As you may have seen I have a test upload question already asked on gh ( https://github.com/denoland/deno/discussions/20983 ) which was answerd and I was able to make a upload via curl. Now to start a more useable programm I have some newbie questions an hope to get here some answers or pointers from which I can start to learn. What's the best way to configure a Application, something similar to https://github.com/git001/caddyv2-upload/blob/main/docker-files/opt/webroot/config/Caddyfile which puts the data into this struct https://github.com/git001/caddyv2-upload/blob/main/upload.go#L29-L51 . What I have learned from ( https://www.typescriptlang.org/docs/handbook/ ) is that typescript is a typed js so maybe there is such something similar like the struct in go. Is there a "best practice" document for Projects which have some frontend/backend code? What I have in mind is such a directory structure β”œβ”€β”€ backend β”œβ”€β”€ common β”‚ └── validators β”œβ”€β”€ frontend β”œβ”€β”€ static β”œβ”€β”€ tests Thank you that you have read until this line. πŸ™‡
6 Replies
Deno AI Helper
Deno AI Helperβ€’15mo ago
Hello Alex, welcome to the Deno community! πŸ¦• In Deno, we strive to make configuration as simple as possible. According to the documentation, Deno supports a configuration file that allows you to customize the built-in TypeScript compiler, formatter, and linter. The configuration file supports .json and .jsonc extensions. Since v1.18, Deno will automatically detect a deno.json or deno.jsonc configuration file if it’s in your current working directory or parent directories. The --config flag can be used to specify a different configuration file. Here is an example of a full configuration file:
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"lint": {
"include": ["src/"],
"exclude": ["src/testdata/", "data/fixtures/**/*.ts"],
"rules": {
"tags": ["recommended"],
"include": ["ban-untagged-todo"],
"exclude": ["no-unused-vars"]
}
},
"fmt": {
"useTabs": true,
"lineWidth": 80,
"indentWidth": 4,
"semiColons": true,
"singleQuote": true,
"proseWrap": "preserve",
"include": ["src/"],
"exclude": ["src/testdata/", "data/fixtures/**/*.ts"]
}
}
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"lint": {
"include": ["src/"],
"exclude": ["src/testdata/", "data/fixtures/**/*.ts"],
"rules": {
"tags": ["recommended"],
"include": ["ban-untagged-todo"],
"exclude": ["no-unused-vars"]
}
},
"fmt": {
"useTabs": true,
"lineWidth": 80,
"indentWidth": 4,
"semiColons": true,
"singleQuote": true,
"proseWrap": "preserve",
"include": ["src/"],
"exclude": ["src/testdata/", "data/fixtures/**/*.ts"]
}
}
As for the project structure, there isn't a strict rule or best practice defined in the documentation. The structure you proposed seems reasonable. You can have separate directories for frontend, backend, common code, static files, and tests. This is a common structure in many web development projects and should work well with Deno. Remember, the most important thing is that the structure makes sense for your project and
Deno AI Helper
Deno AI Helperβ€’15mo ago
team. It should help you keep the project organized and maintainable. I hope this helps! If you have any more questions, feel free to ask. Happy coding! πŸ¦•
Deno AI Helper
Deno AI Helperβ€’15mo ago
πŸ¦• Oops! Can you pinpoint where I went wrong to help me improve? πŸ“ˆ
alex-009
alex-009OPβ€’14mo ago
I don't want to configure Deno, I want to configure the application which I develop WITH deno thank you @eric.uhd for your time to answer my question. Will take a look into your suggestions. Here the answer to the question
I don’t understand what you mean by configure the application you develop.
My app offers some config items like max upload size or upload directory this could be for every use case different and therefore should it be possibel to add a config.ts/config.json or something similar to set the application variables from outsite the application
Mark G
Mark Gβ€’14mo ago
Another option for configuration is via environment vars, this is esp useful if you want to pass secrets, or configuration independently of deployment (many deployment services, incl Deno Deploy, allow you to set and change env vars without redeploying), dotenv helps greatly with this, by reading a local .env file... https://deno.land/std@0.204.0/dotenv/mod.ts
alex-009
alex-009OPβ€’14mo ago
Great. tahnks. I have seen in that codes something which I have in mind https://github.com/lumeland/lume/blob/master/mod.ts => https://github.com/lumeland/lume/blob/master/core/site.ts#L43 . Thanks to lume developer for that App and solution πŸ™‡β€β™‚οΈ

Did you find this page helpful?