├── .npmrc ├── .gitattributes ├── static ├── favicon.png ├── robots.txt ├── img │ └── circle.png ├── css │ └── style.css └── js │ ├── popper.min.js │ └── bootstrap.bundle.min.js ├── src ├── routes │ ├── +page.ts │ ├── contact │ │ ├── +page.svelte │ │ └── +page.server.ts │ ├── +page.svelte │ ├── +page.server.ts │ ├── search │ │ └── +server.ts │ ├── pagination │ │ └── +server.ts │ └── +layout.svelte ├── hooks.server.ts ├── app.d.ts ├── db │ ├── mongo.ts │ └── collections.ts ├── app.html └── lib │ └── components │ ├── contact │ └── ContactForm.svelte │ └── home │ └── Repositories.svelte ├── vite.config.ts ├── .env.example ├── tsconfig.json ├── svelte.config.js ├── eslint.config.js ├── package.json ├── README.md └── .gitignore /.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bberkay/sveltekit-mongodb/HEAD/static/favicon.png -------------------------------------------------------------------------------- /static/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /static/img/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bberkay/sveltekit-mongodb/HEAD/static/img/circle.png -------------------------------------------------------------------------------- /src/routes/+page.ts: -------------------------------------------------------------------------------- 1 | // since there's no dynamic data here, we can prerender 2 | // it so that it gets served as a static asset in production 3 | export const prerender = true; 4 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { sveltekit } from '@sveltejs/kit/vite'; 2 | import { defineConfig } from 'vite'; 3 | 4 | export default defineConfig({ 5 | plugins: [sveltekit()] 6 | }); 7 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # MAIL SETTINGS 2 | MAIL_HOST = "smtpout.secureserver.net" 3 | MAIL_PORT = "465" 4 | MAIL_USERNAME = "XXX@domain.com" 5 | MAIL_PASSWORD = "XXXXXXXXXX" 6 | 7 | # MONGO SETTINGS 8 | MONGO_URL = "mongodb://localhost/database" 9 | -------------------------------------------------------------------------------- /src/hooks.server.ts: -------------------------------------------------------------------------------- 1 | import { connect } from '$db/mongo'; 2 | 3 | // Connect to MongoDB before starting the server 4 | connect().then(():void => { 5 | console.log("MongoDB started"); 6 | }).catch((e: Error) => { 7 | console.log("MongoDB failed to start"); 8 | console.log(e); 9 | }); 10 | -------------------------------------------------------------------------------- /src/app.d.ts: -------------------------------------------------------------------------------- 1 | // See https://svelte.dev/docs/kit/types#app.d.ts 2 | // for information about these interfaces 3 | declare global { 4 | namespace App { 5 | // interface Error {} 6 | // interface Locals {} 7 | // interface PageData {} 8 | // interface PageState {} 9 | // interface Platform {} 10 | } 11 | } 12 | 13 | export {}; 14 | -------------------------------------------------------------------------------- /src/routes/contact/+page.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 |
This is main branch, you can also check svelte-4 branch to see svelte 4 version. Live Demo (The site may open slowly because I deployed the project to a free hosting server. To avoid problems that may arise due to a slow connection and to be able to use features that are not available in the demo, I recommend that you download the project to your machine and try it.)
The main purpose of this project is to learn how to use MongoDB with Sveltekit so it is very simple and detailed with comments. 13 | I used MongoDB Atlas for the database and Nodemailer for the contact form.
14 |
15 |
16 | {repository.description}
103 | 104 | {#each repository.tags as tag} 105 | {tag} 106 | {/each} 107 | 108 |