Skip to content

Commit

Permalink
okay, deno, no more "unstable sloppy imports"
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel-Mutebi committed Dec 20, 2024
1 parent b73f4f9 commit 1947264
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In regards to the design, I wanted it to be reminiscent of an early 2000s websit

### Model

**directory**: `/model (db)`
**directory**: `/database`

Originally, I used a JavaScript object for data storage. But because my code was SOLID (that's a pun hinting at the design principles acronym 🙂), I easily migrated to a **PostgreSQL** database with the help of the **pg** (node-postgres) library.

Expand Down
2 changes: 1 addition & 1 deletion controllers/getControllers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RequestHandler } from "express";
import { format as dateFormatter } from "date-fns";
import { getMessages, getMessage } from "../model (db)/query.ts";
import { getMessages, getMessage } from "../database/query.ts";

const index: RequestHandler = async(req, res) => {
const messages = await getMessages();
Expand Down
2 changes: 1 addition & 1 deletion controllers/postControllers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RequestHandler } from "express";
import { validationResult } from "express-validator";
import { addMessage } from "../model (db)/query.ts";
import { addMessage } from "../database/query.ts";
import { postMessageValidator } from "../middlewares/validators.ts";

const postMessage: RequestHandler[] = [
Expand Down
3 changes: 2 additions & 1 deletion model (db)/pool.ts → database/pool.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import dotenv from "dotenv";
import { Pool } from "pg";
import pg from "pg";

dotenv.config();

const { Pool } = pg;
const pool = new Pool({ connectionString: process.env.DATABASE_URL });

export default pool;
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion model (db)/query.ts → database/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Message from "../types/MessageInterface";
import Message from "../types/MessageInterface.ts";
import pool from "./pool.ts";

async function getMessages(): Promise<Message[]> {
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dotenv.config();
const app = express();
const PORT = process.env.PORT;

app.set("views", path.join(__dirname, "views"));
app.set("views", path.join(import.meta.dirname, "views"));
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(express.urlencoded({ extended: false }));
Expand Down
29 changes: 18 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"populate": "deno './model (db)/populate.ts'"
"populate": "deno './database/populate.ts'"
},
"keywords": [],
"author": "Ariel Robert Mutebi",
Expand Down

1 comment on commit 1947264

@deno-deploy
Copy link
Contributor

@deno-deploy deno-deploy bot commented on 1947264 Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

UNCAUGHT_EXCEPTION

ReferenceError: process is not defined
    at file:///src/database/pool.ts:7:43

Please sign in to comment.