> For the complete documentation index, see [llms.txt](https://uthersunlighter.gitbook.io/uthersunlighter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://uthersunlighter.gitbook.io/uthersunlighter/lucidity.md).

# Lucidity

#### **1. Prerequisites**

* Ensure you have **Node.js** version **20.12.2** or higher installed on your machine.
* Install **npm** (comes with Node.js) and **TypeScript** globally:

```bash
npm install -g typescript
```

#### **2. Create a Node.js Project**

1. **Open your terminal**.
2. **Create a new project directory** and navigate to it:

   ```bash
   mkdir lucidity-project
   cd lucidity-project
   ```
3. **Initialize a new Node.js project**:

   ```bash
   npm init -y
   ```

#### **3. Install Lucid Core and Other Dependencies**

Run the following command to install Lucid Core along with any other necessary packages:

```bash
npm install @lucidcms/core express dotenv cors
```

* `express`: For setting up the server.
* `dotenv`: For managing environment variables.
* `cors`: To enable Cross-Origin Resource Sharing.

#### **4. Create Configuration Files**

**4.1 Environment Variables**

Create a `.env` file in the root of your project to store sensitive information:

```bash
touch .env
```

Add your configuration settings:

```env
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=user@example.com
SMTP_PASS=yourpassword
```

**4.2 Lucidity Configuration**

Create a configuration file named `lucid.config.ts` in the root of your project:

```bash
touch lucid.config.ts
```

Here’s an example configuration file:

```typescript
import { defineConfig } from '@lucidcms/core';

export default defineConfig({
  collections: [
    {
      name: 'posts',
      fields: [
        { name: 'title', type: 'string' },
        { name: 'content', type: 'text' },
        { name: 'author', type: 'string' },
        { name: 'publishedDate', type: 'date' },
      ],
    },
  ],
  locales: ['en', 'fr'],
  email: {
    provider: 'smtp',
    options: {
      host: process.env.SMTP_HOST,
      port: Number(process.env.SMTP_PORT),
      auth: {
        user: process.env.SMTP_USER,
        pass: process.env.SMTP_PASS,
      },
    },
  },
});
```

#### **5. Importing and Starting Lucidity**

Create an entry file, for example, `index.ts`:

```typescript
import { lucid } from '@lucidcms/core';
import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';

dotenv.config();

const app = express();
const PORT = process.env.PORT || 8080;

app.use(cors());
app.use(express.json());

async function startLucid() {
  await lucid.start();
  console.log(`Lucid is running on http://localhost:${PORT}/login`);
}

app.listen(PORT, () => {
  console.log(`Server is running on http://localhost:${PORT}`);
});

startLucid();
```

#### **6. Running Your Project**

To compile TypeScript and run your project, use the following command in your terminal:

```bash
tsc index.ts && node index.js
```

Alternatively, you can set up a script in your `package.json` to simplify this:

```json
"scripts": {
  "start": "tsc index.ts && node index.js"
}
```

Then run:

```bash
npm start
```

#### **7. Testing Your Setup**

Navigate to `http://localhost:8080/login` to see Lucid in action. The default username is `admin`, and the password is `password`. You will be prompted to change this password on first login.

#### **8. Additional Features**

**8.1 Adding Middleware**

You can add custom middleware for logging requests or handling errors:

```typescript
app.use((req, res, next) => {
  console.log(`${req.method} request for '${req.url}'`);
  next();
});

// Error handling middleware
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).send('Something broke!');
});
```

**8.2 Setting Up Routes**

You can define custom routes for handling API requests:

```typescript
app.get('/api/posts', async (req, res) => {
  // Logic to fetch posts from Lucidity CMS
});

app.post('/api/posts', async (req, res) => {
  // Logic to create a new post in Lucidity CMS
});
```

#### **9. Monitoring and Maintenance**

Keep an eye on the logs for any errors or warnings while running the server:

```bash
tail -f logs/lucid.log # If you set up logging functionality.
```

#### **10. Deployment Considerations**

When deploying your Lucidity node, consider using services like Heroku, DigitalOcean, or AWS. Make sure to set environment variables securely in your deployment environment.

By following these steps, you should have a fully functional Lucidity node ready for development!
