Skip to content

installation

Azizul Hakim edited this page Nov 1, 2024 · 2 revisions

Prerequisites

Before installing nestjs-xsecurity, ensure you have:

  • Node.js (v14 or higher)
  • A NestJS project (v9 or higher)
  • Package manager (npm, yarn, or pnpm)

Package Installation

# Using npm
npm install nestjs-xsecurity

# Using yarn
yarn add nestjs-xsecurity

# Using pnpm
pnpm add nestjs-xsecurity

Verify Installation

Check your package.json dependencies:

{
  "dependencies": {
    "nestjs-xsecurity": "^x.x.x"
  }
}

Setup Options

After installing the package, you can choose between automated or manual setup.

Option 1: Automated Setup (Recommended)

Run our CLI tool to automatically set up configuration:

npx nestjs-xsecurity install

This command will:

  • Generate a secure random secret
  • Set up required environment variables
  • Create an initial configuration file or update the existing .env

Option 2: Manual Setup

If you prefer manual configuration:

  1. Generate a secure secret:
# Using node
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

# Using openssl
openssl rand -base64 32
  1. Create or update your .env file with the generated secret:
# Required
XSECURITY_SECRET=your-generated-secret-key

# Optional (with defaults)
XSECURITY_ENABLED=true
XSECURITY_MAX_ATTEMPTS=5
XSECURITY_DECAY_MINUTES=1

Next Steps

Troubleshooting Installation

If you encounter installation issues:

  1. Clear your package manager cache and try reinstalling
  2. Verify Node.js and NestJS versions
  3. Check for conflicting dependencies