# Lucidity node instal guide


By [@Nelson](https://paragraph.com/@nelson-5) · 2024-10-21

---

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
-------------------------

1.  Set up a Node.js project
    
        mkdir lucid-project
        cd lucid-project
        npm init -y
        
    
2.  Install Lucid Core
    
        npm install @adonisjs/lucid
        
    
3.  Configure Lucid
    
        npx @adonisjs/lucid configure
        
    
4.  Update package.json Add the following to your package.json:
    
        {
          "type": "module",
          "scripts": {
            "start": "node ace serve --watch",
            "build": "node ace build --production"
          }
        }
        
    
5.  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,
            }
          }
        })
        
    
6.  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
-------------

1.  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
        }
        
    
2.  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)
          }
        }
        
    
3.  Run the migration
    
        node ace migration:run
        
    
4.  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)
          }
        }
        
    
5.  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'])

---

*Originally published on [@Nelson](https://paragraph.com/@nelson-5/lucidity-node-instal-guide)*
