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
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:
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 andteam. 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! π¦
π¦ Oops! Can you pinpoint where I went wrong to help me improve? π
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 applicationAnother 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.tsGreat. 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 πββοΈ