D
Deno

help

Best way for application config in deno/ts?

Aalex-00910/30/2023
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. πŸ™‡
DAHDeno AI Helper10/30/2023
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
DAHDeno AI Helper10/30/2023
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! πŸ¦•
DAHDeno AI Helper10/30/2023
πŸ¦• Oops! Can you pinpoint where I went wrong to help me improve? πŸ“ˆ
Aalex-00910/31/2023
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
MGMark G10/31/2023
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
Aalex-00910/31/2023
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 πŸ™‡β€β™‚οΈ

Looking for more? Join the community!

Recommended Posts
Error trying to connect: Connection reset by peer (os error 104)Hello, i'm trying to deploy a my Fresh website using a Ubuntu 22.04 server but when I try to run my 500 on deno.land/x/fp_ts with ?s=eitherThe actual URL is https://deno.land/x/fp_ts@v2.11.4/mod.ts?s=eitherDeno.test without Deno namespace ?Hi there, Does someone know if it's possible to run a test from `Deno.test` without the Deno namespWASM / Extract and manipulate Array of DateI try to extract and manipulate an array of date in a function The rust fn doesn't compile. How to error: Uncaught Error: Input watch path is neither a file nor a directory.Im encountering a weird error when I run a code in Windows that was initially created in a OSX. It ES Module mocking workaroundHello all, I've been using Deno and Fresh for the past few weeks on a personal project and I love itFontAwesome Import into island component not working as expectedHey, I want to use FontAwesome with a Fresh component inside my island folder. I followed the follKV - Not possible to maintain in real world?I have a question regarding Deno **KV**: I just checked the docs and it seems straight forward so faGet a Parameter Value in Oakso if I set up a router like this ```router.get("/:id", (ctx) => {/*handle router context*/})```thenreadTextFile() not working?what is this? its there but its not workingkv store key granualityHow cheap are the `kv.get` operations? Say I have a userprofile with 3 fields, should I create 3 kedeno tap metadataHello. I am running deno tests with `deno test --reporter=tap`. I would like to add additional fieldUsing ESBuild with DenoHey, is anyone more familiar with ESBuild? I am currently trying to transpile my Deno TypeScript proMultiple subdomainsHow can I listen for incoming http request on multiple subdomains?Can't upgrade request to websocketI want to use a websocket in one of my middlewares. But I keep getting an error saying I can't upgrAccess `navigator.geolocation` in deno runtimeHello, is it possible to access `navigator.geolocation` in the deno runtime?Tracking Down Lost MemoryHi, I have a long running service that creates many `JsRuntime`s over time and I have found that I `deno run` ignores @deno-types?```ts Uncaught SyntaxError: The requested module 'pg' does not provide an export named 'Pool' importWhere is my Twitter access token with Deno KV Oauth?I signed in successfully and now the Deno KV database is just storing `true`. It's not enough to intHow do I import the stripe SDK into my fresh.js projectHi there! How do I import the stripe SDK into my fresh.js project? Im struggling with my deno.json f