# Lucidity node instal guide **Published by:** [@Nelson](https://paragraph.com/@nelson-5/) **Published on:** 2024-10-21 **URL:** https://paragraph.com/@nelson-5/lucidity-node-instal-guide ## Content System Requirements Node.js version 20.12.2 or higher npm 8.x or higher (or yarn/pnpm) Supported databases: PostgreSQL 10+ MySQL 5.7+ SQLite 3.8.8+ Microsoft SQL Server 2012+ Step-by-Step Installation Set up a Node.js project mkdir lucid-project cd lucid-project npm init -y Install Lucid Core npm install @adonisjs/lucid Configure Lucid npx @adonisjs/lucid configure Update package.json Add the following to your package.json: { "type": "module", "scripts": { "start": "node ace serve --watch", "build": "node ace build --production" } } Create database configuration file Create a file config/database.ts: import { defineConfig } from '@adonisjs/lucid' export default defineConfig({ connection: 'postgres', connections: { postgres: { driver: 'postgres', host: process.env.DB_HOST, port: Number(process.env.DB_PORT), user: process.env.DB_USER, password: process.env.DB_PASSWORD, database: process.env.DB_NAME, } } }) Set up environment variables Create a .env file: DB_CONNECTION=postgres DB_HOST=127.0.0.1 DB_PORT=5432 DB_USER=lucid DB_PASSWORD=your_password DB_NAME=lucid_db Usage Example Create a model Create a file app/Models/User.ts: import { BaseModel, column } from '@adonisjs/lucid/orm' export default class User extends BaseModel { @column({ isPrimary: true }) public id: number @column() public email: string @column() public name: string } Create a migration node ace make:migration create_users_table Edit the created migration file: import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { protected tableName = 'users' public async up() { this.schema.createTable(this.tableName, (table) => { table.increments('id') table.string('email').notNullable().unique() table.string('name') table.timestamp('created_at', { useTz: true }) table.timestamp('updated_at', { useTz: true }) }) } public async down() { this.schema.dropTable(this.tableName) } } Run the migration node ace migration:run Use the model in your code Create a file app/Controllers/UsersController.ts: import User from '../Models/User' export default class UsersController { public async index() { return await User.all() } public async store({ request }) { const userData = request.only(['email', 'name']) return await User.create(userData) } } Set up routes In the start/routes.ts file: import Route from '@adonisjs/core/route' import UsersController from '../app/Controllers/UsersController' Route.get('/users', [UsersController, 'index']) Route.post('/users', [UsersController, 'store']) ## Publication Information - [@Nelson](https://paragraph.com/@nelson-5/): Publication homepage - [All Posts](https://paragraph.com/@nelson-5/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@nelson-5): Subscribe to updates - [Twitter](https://twitter.com/valid_nelson): Follow on Twitter