DEV Community

Sokhavuth TIN
Sokhavuth TIN

Posted on • Edited on

2 1

Blog Engine with Fresh: Environment Variable & Database


GitHub: https://github.com/Sokhavuth/deno-fresh
Deno Deploy: https://khmerweb-fresh.deno.dev/


// setting.js

function setting(){
    const configure = {
        site_title: "Multimedia",
        page_title: "Home",
        message: "",
    }

    return configure
}


import { config } from "config";
await config({export: true});
const secret_key = Deno.env.get("SECRET_KEY");


import { MongoClient } from "mongodb";
const client = await new MongoClient();
await client.connect(Deno.env.get('DATABASE_URI'));
const mydb = client.database(Deno.env.get('DB_NAME'));


import { connect } from "redis"
const myredis = await connect({
    hostname: Deno.env.get('REDIS_URI'),
    port: parseInt(Deno.env.get('REDIS_PORT')),
    password: Deno.env.get('REDIS_PASSWORD'),
});


export { setting, secret_key, mydb, myredis }
Enter fullscreen mode Exit fullscreen mode
// import_map.json
{
  "imports": {
    "$fresh/": "https://deno.land/x/fresh@1.0.2/",
    "preact": "https://esm.sh/preact@10.10.0",
    "preact/": "https://esm.sh/preact@10.10.0/",
    "preact-render-to-string": "https://esm.sh/preact-render-to-string@5.2.1?external=preact",
    "setting": "./setting.js",
    "config": "https://deno.land/std@0.147.0/dotenv/mod.ts",
    "jwt": "https://deno.land/x/djwt@v2.2/mod.ts",
    "mongodb": "https://deno.land/x/mongo@v0.30.1/mod.ts",
    "redis": "https://deno.land/x/redis@v0.26.0/mod.ts",
    "bcrypt": "./bcrypt.ts",
    "cookies": "https://deno.land/std@0.150.0/http/cookie.ts"
  }
}
Enter fullscreen mode Exit fullscreen mode
// .env

SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DATABASE_URI=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DB_NAME=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
REDIS_URI=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
REDIS_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
REDIS_PORT=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Enter fullscreen mode Exit fullscreen mode

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs