A professional starter template for setting up Prisma ORM with TypeScript and MariaDB in a Node.js environment. This setup uses modern ESM (nodenext) and the specialized MariaDB adapter.
Follow these steps to initialize the project from scratch.
Create your project directory and initialize npm.
mkdir prisma-test
cd prisma-test
npm init -y
Install core production packages:
npm install @prisma/client @prisma/adapter-mariadb dotenv
Install development tools:
npm install prisma @types/node nodemon tsx typescript --save-dev
Initialize TypeScript and update tsconfig.json to support modern ESM modules.
Command:
npx tsc --init
Updated tsconfig.json:
{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"target": "esnext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": [
"src/**/*",
"prisma/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}
Update package.json to enable ES Modules and define scripts.
- Set
"type": "module". - Add the following scripts:
"scripts": {
"dev": "nodemon",
"build": "tsc",
"start": "node dist/index.js"
}
Create a nodemon.json file in the root directory to automate the development workflow using tsx.
File: nodemon.json
{
"watch": [
"src/**/*",
"prisma/**/*"
],
"ext": "ts",
"ignore": [
"node_modules/**/*",
"build/**/*"
],
"exec": "tsx src/index.ts"
}
Initialize Prisma with MySQL as the provider and set a custom output path.
npx prisma init --datasource-provider mysql --output ./src/generated/prisma
Update your .env file with your credentials.
Standard Connection:
DATABASE_URL="mysql://USER:PASS@HOST:PORT/DATABASE"
Connection with SSL:
DATABASE_URL="mysql://USER:PASS@HOST:PORT/DATABASE?ssl-ca=assets/certs/ca-certificate.crt&ssl-mode=REQUIRED"
Important
Ensure the CA certificate is placed in the correct file path as specified in your URL string.
Pull your existing database schema and generate the Prisma Client.
npx prisma db pull
npx prisma db generate
Create a configuration file to initialize the Prisma Client with the MariaDB adapter.
File: src/config/prisma.ts
import 'dotenv/config';
import { PrismaMariaDb } from '@prisma/adapter-mariadb';
import { PrismaClient } from '../generated/prisma/index.js';
const adapter = new PrismaMariaDb(process.env.DATABASE_URL!);
export const prisma = new PrismaClient({ adapter });Start your development server with npm run dev.
File: src/index.ts
import { prisma } from "./config/prisma.js";
async function main() {
// Use the prisma client as usual
// const users = await prisma.user.findMany();
}
main().catch(console.error);- Runtime: Node.js (ESM)
- Language: TypeScript
- ORM: Prisma
- Database: MariaDB
- Development: Nodemon, tsx