generated from Timofey-Makhankov/Node-Express-JS-Template
Initial commit
This commit is contained in:
5
src/app.ts
Normal file
5
src/app.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import express, { Express } from "express"
|
||||
|
||||
const app: Express = express()
|
||||
|
||||
export default app
|
||||
5
src/db/config.ts
Normal file
5
src/db/config.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import "dotenv/config"
|
||||
import { drizzle } from "drizzle-orm/libsql"
|
||||
import env from "../env"
|
||||
|
||||
export const db = drizzle({ connection: { url: env.DB_FILE_NAME } })
|
||||
2
src/db/schema.ts
Normal file
2
src/db/schema.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
// @ts-ignore: Remove, when creating Schemas
|
||||
import { int, sqliteTable, text } from "drizzle-orm/sqlite-core"
|
||||
32
src/env.ts
Normal file
32
src/env.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { config } from "dotenv";
|
||||
import { expand } from "dotenv-expand";
|
||||
import { z, ZodError } from "zod";
|
||||
|
||||
expand(config({
|
||||
path: ".env",
|
||||
}));
|
||||
|
||||
const EnvSchema = z.object({
|
||||
NODE_ENV: z.string().default("development"),
|
||||
LOG_LEVEL: z.enum(["fatal", "error", "warn", "info", "debug", "trace"]),
|
||||
PORT: z.coerce.number().default(3000),
|
||||
DB_FILE_NAME: z.string().url(),
|
||||
});
|
||||
|
||||
export type env = z.infer<typeof EnvSchema>;
|
||||
|
||||
// eslint-disable-next-line import/no-mutable-exports, ts/no-redeclare
|
||||
let env: env;
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line node/no-process-env
|
||||
env = EnvSchema.parse(process.env);
|
||||
}
|
||||
catch (e) {
|
||||
const error = e as ZodError;
|
||||
console.error("Invalid env:");
|
||||
console.error(error.flatten().fieldErrors);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
export default env;
|
||||
6
src/index.ts
Normal file
6
src/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import app from "./app"
|
||||
import env from "./env"
|
||||
|
||||
app.listen(env.PORT, () => {
|
||||
console.log(`Express Server is running on http://localhost:${env.PORT}`)
|
||||
})
|
||||
5
src/routes/example.ts
Normal file
5
src/routes/example.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import app from "../app"
|
||||
|
||||
app.get("/", (_req, res) => {
|
||||
res.send("Hello world!")
|
||||
})
|
||||
Reference in New Issue
Block a user