|
| 1 | +# Sveltekit & MongoDB |
| 2 | + |
| 3 | +[](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-sveltekit-mongodb-template%26template_owner%3DDefangSamples) |
| 4 | + |
| 5 | +This is a project that demonstrate both client side component rendering and hydration as well as serverside rendering with external API route configuration. Furthermore, there is also a mongodb connection (not hosted on the atlas) to cache the queried results. |
| 6 | + |
| 7 | +## NOTE |
| 8 | + |
| 9 | +This sample showcases how you could deploy a full-stack application with Defang and Sveltekit. However, it deploys mongodb as a defang service. Defang [services](https://12factor.net/processes) are ephemeral and should not be used to run stateful workloads in production as they will be reset on every deployment. For production use cases you should use a managed database like RDS, Aiven, or others. In the future, Defang will help you provision and connect to managed databases. |
| 10 | + |
| 11 | +## Essential Setup Files |
| 12 | + |
| 13 | +1. Download [Defang CLI] (https://github.com/DefangLabs/defang) |
| 14 | +2. (optional) If you are using [Defang BYOC] (https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated your AWS account. |
| 15 | +3. (optional for local development) [Docker CLI] (https://docs.docker.com/engine/install/) |
| 16 | + |
| 17 | +## Prerequisite |
| 18 | + |
| 19 | +1. Download [Defang CLI] (https://github.com/DefangLabs/defang) |
| 20 | +2. (optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) make sure you have properly |
| 21 | +3. [Docker CLI] (https://docs.docker.com/engine/install/) |
| 22 | + |
| 23 | +4. [NodeJS] (https://nodejs.org/en/download/package-manager) |
| 24 | + |
| 25 | +## Development |
| 26 | + |
| 27 | +For development, we use a local container. This can be seen in the compose.yaml and /src/routes/api/songs/+server.js file and the server.js file where we create a pool of connections. To run the sample locally after clonging the respository, you can run on docker by doing |
| 28 | + |
| 29 | +1. docker compose up --build |
| 30 | + |
| 31 | +## A Step-by-Step Guide |
| 32 | + |
| 33 | +1. Open the terminal and type `defang login` |
| 34 | +2. Type `defang compose up` in the CLI |
| 35 | +3. Your app should be up and running with Defang in minutes! |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +Title: SvelteKit & MongoDB |
| 40 | + |
| 41 | +Short Description: A full-stack application using SvelteKit for the frontend and MongoDB for the database. |
| 42 | + |
| 43 | +Tags: SvelteKit, MongoDB, Full-stack, Node.js, JavaScript |
| 44 | + |
| 45 | +Languages: nodejs |
0 commit comments