Demo: https://self-learning-demo.vercel.app
nx serve
Requirements:
- Node.js
- Postgres instance
- Environment variables (see .env.example):
DATABASE_URL="postgresql://username:password@localhost:5432/SelfLearningDb"
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="YOUR_SECRET"
- You can generate a secret via this command:
openssl rand -base64 32
- You can generate a secret via this command:
# Install dependencies
npm ci
# [DEMO ONLY] Apply database schema
npm run prisma db push --accept-data-loss
# [DEMO ONLY] Seed database with demo data
npm run prisma db seed
# Build application
npm run build --prod
# Start server (at http://localhost:3000)
npm run start:prod
# Run all tests
npm run test
# Testing a specific application or library
nx test [APPLICATION_NAME / LIBRARY_NAME] [--watch]
When using the Jest Runner extension during development, you will see a Run
and Debug
CodeLens button above your tests. Use these to start individual tests. Additionally, you may want to configure
"jestrunner.runOptions": ["--watch"]
in your VS Code's settings.json
(or using the Settings UI Extensions > Jest-Runner Config > Run Options > Add Item -> "--watch"
). Afterwards, your tests will automatically start with watch
mode enabled.
In VS Code, press F1
to open the command palette and search for Extensions: Show Recommended Extensions
. Afterwards, the following plugins will appear in your sidebar with an Install
button.
- Prettier: Code formatter
- ESLint: Static analysis and coding style guidelines
- Tailwind CSS IntelliSense: IntelliSense for Tailwind CSS classes
- Nx Console: UI for Nx commands
- Jest Runner: Simple way to run or debug a single (or multiple) tests from context-menu or via code lens
- Prisma: Adds syntax highlighting, formatting, auto-completion, jump-to-definition and linting for .prisma files
This project uses Prisma for database access.
To interact with the database, you can use code like the following:
import { User } from "@prisma/client"; // User is generated by Prisma from our schema
import { database } from "@self-learning/database";
function getUserById(id: string): Promise<User> {
// all properties (user, id, ...) are type-safe!
return database.user.findUnique({
where: {
id: id
}
});
}
Development only: After making changes to the database schema (libs/data-access//database/prisma/schema.prisma), use the following command to push these changes to the database:
npm run prisma db push
Prisma generates code according to the defined database schema. After making changes to the schema, you must trigger the code generation via the following command:
npm run prisma generate
Fill database with demo data, which is defined in seed.ts:
npm run prisma seed