initialised Project template for Express with Sqlite Drizzle
This commit is contained in:
4
.env.example
Normal file
4
.env.example
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
DB_FILE_NAME=file:local.db
|
||||||
|
PORT=3000
|
||||||
|
NODE_ENV=development
|
||||||
|
LOG_LEVEL=info
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -130,3 +130,5 @@ dist
|
|||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
# Local DB instance
|
||||||
|
*.db
|
||||||
|
|||||||
51
.vscode/settings.json
vendored
Normal file
51
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
// Disable the default formatter, use eslint instead
|
||||||
|
"prettier.enable": false,
|
||||||
|
"editor.formatOnSave": false,
|
||||||
|
|
||||||
|
// Auto fix
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.fixAll.eslint": "explicit",
|
||||||
|
"source.organizeImports": "never"
|
||||||
|
},
|
||||||
|
|
||||||
|
// Silent the stylistic rules in you IDE, but still auto fix them
|
||||||
|
"eslint.rules.customizations": [
|
||||||
|
{ "rule": "style/*", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "format/*", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "*-order", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
||||||
|
{ "rule": "*semi", "severity": "off", "fixable": true }
|
||||||
|
],
|
||||||
|
|
||||||
|
// Enable eslint for all supported languages
|
||||||
|
"eslint.validate": [
|
||||||
|
"javascript",
|
||||||
|
"javascriptreact",
|
||||||
|
"typescript",
|
||||||
|
"typescriptreact",
|
||||||
|
"vue",
|
||||||
|
"html",
|
||||||
|
"markdown",
|
||||||
|
"json",
|
||||||
|
"json5",
|
||||||
|
"jsonc",
|
||||||
|
"yaml",
|
||||||
|
"toml",
|
||||||
|
"xml",
|
||||||
|
"gql",
|
||||||
|
"graphql",
|
||||||
|
"astro",
|
||||||
|
"svelte",
|
||||||
|
"css",
|
||||||
|
"less",
|
||||||
|
"scss",
|
||||||
|
"pcss",
|
||||||
|
"postcss"
|
||||||
|
]
|
||||||
|
}
|
||||||
12
drizzle.config.ts
Normal file
12
drizzle.config.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { defineConfig } from 'drizzle-kit'
|
||||||
|
import env from './src/env'
|
||||||
|
import 'dotenv/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
out: './drizzle',
|
||||||
|
schema: './src/db/schema.ts',
|
||||||
|
dialect: 'sqlite',
|
||||||
|
dbCredentials: {
|
||||||
|
url: env.DB_FILE_NAME,
|
||||||
|
},
|
||||||
|
})
|
||||||
5
eslint.config.mjs
Normal file
5
eslint.config.mjs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import antfu from '@antfu/eslint-config'
|
||||||
|
|
||||||
|
export default antfu({
|
||||||
|
formatters: true,
|
||||||
|
})
|
||||||
33
package.json
Normal file
33
package.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "node-express-js-template",
|
||||||
|
"type": "module",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "",
|
||||||
|
"author": "Timofey Makhankov",
|
||||||
|
"license": "MIT",
|
||||||
|
"keywords": [],
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "tsx watch src/index.ts",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"lint:fix": "pnpm run lint --fix",
|
||||||
|
"db:push": "npx drizzle-kit push"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@libsql/client": "^0.15.5",
|
||||||
|
"dotenv": "^16.5.0",
|
||||||
|
"dotenv-expand": "^12.0.2",
|
||||||
|
"drizzle-orm": "^0.43.1",
|
||||||
|
"express": "^5.1.0",
|
||||||
|
"zod": "^3.24.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@antfu/eslint-config": "^4.13.0",
|
||||||
|
"@types/express": "^5.0.1",
|
||||||
|
"@types/node": "^22.15.17",
|
||||||
|
"drizzle-kit": "^0.31.1",
|
||||||
|
"eslint": "^9.26.0",
|
||||||
|
"eslint-plugin-format": "^1.0.1",
|
||||||
|
"tsx": "^4.19.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
4770
pnpm-lock.yaml
generated
Normal file
4770
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
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!")
|
||||||
|
})
|
||||||
20
tsconfig.json
Normal file
20
tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"composite": true,
|
||||||
|
"target": "ESNext",
|
||||||
|
"lib": [
|
||||||
|
"ESNext"
|
||||||
|
],
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"strict": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user