Quick Start Guide

Get started with XyPriss in a few simple steps.

Installation

xfpm i xypriss

For additional security features:

xfpm i xypriss-security

Method 1: Using XyPriss CLI (Recommended)

The CLI provides the fastest way to initialize a new project with best practices:

# Install the CLI globally
npm install -g xypriss-cli

# Create a new project
xypcli init

# Start development
cd your-project-name
xfpm dev

The CLI automatically generates:

  • Project structure with TypeScript configuration
  • Authentication setup (optional)
  • File upload support (optional)
  • Multi-server configuration (optional)
  • Security middleware configuration

Method 2: Manual Setup

Basic Server

import { createServer } from "xypriss";

const server = createServer({
  server: { port: 3000 },
  security: { enabled: true },
});

server.get("/", (req, res) => {
  res.xJson({ message: "Server running" });
});

server.start(() => {
  console.log(`Server running at http://localhost:${server.getPort()}`);
});

With Routing

import { createServer, Router } from "xypriss";

const app = createServer();
const userRouter = Router();

userRouter.get("/:id", (req, res) => {
  res.xJson({ userId: req.params.id });
});

app.use("/api/users", userRouter);
app.start();

With File Upload

import { createServer, FileUploadAPI } from "xypriss";

const app = createServer({
  fileUpload: {
    enabled: true,
    maxFileSize: 5 * 1024 * 1024, // 5MB
  },
});

const upload = new FileUploadAPI();
await upload.initialize(app.configs?.fileUpload);

app.post("/upload", upload.single("file"), (req, res) => {
  res.xJson({ success: true, file: req.file });
});

app.start();

With Security Configuration

const server = createServer({
  security: {
    enabled: true,
    level: "enhanced",
    cors: {
      origin: ["localhost:*", "*.myapp.com"],
      credentials: true,
    },
    rateLimit: {
      max: 100,
      windowMs: 15 * 60 * 1000,
    },
    csrf: { enabled: true },
    xss: { enabled: true },
  },
});

Common Use Cases

REST API Server

import { createServer } from "xypriss";

const app = createServer({
  security: { enabled: true },
  cors: { origin: "*" },
});

app.get("/api/users", (req, res) => {
  res.xJson({ users: [] });
});

app.post("/api/users", (req, res) => {
  res.xJson({ created: true });
});

app.start();

Multi-Server Setup

const app = createServer({
  multiServer: {
    enabled: true,
    servers: [
      {
        id: "api-server",
        port: 3001,
        routePrefix: "/api",
      },
      {
        id: "admin-server",
        port: 3002,
        routePrefix: "/admin",
        security: { level: "maximum" },
      },
    ],
  },
});

await app.startAllServers(); // or just use the ".start()" method

Production Deployment with XyNginC

import { createServer } from "xypriss";
import XNCP from "xynginc";

const app = createServer({
  plugins: {
    register: [
      XNCP({
        domains: [
          {
            domain: "api.example.com",
            port: 3000,
            ssl: true,
            email: "admin@example.com",
          },
        ],
      }),
    ],
  },
});

app.start();

Next Steps


Troubleshooting

Port Already in Use

XyPriss automatically switches ports if the configured port is unavailable:

const server = createServer({
  server: {
    port: 3000,
    autoPortSwitch: {
      enabled: true,
      portRange: [3000, 3100],
    },
  },
});

CORS Configuration

Enable CORS for specific domains:

const server = createServer({
  security: {
    cors: {
      origin: ["http://localhost:3000", "https://myapp.com"],
      credentials: true,
    },
  },
});

File Upload Configuration

Configure file upload settings:

const server = createServer({
  fileUpload: {
    enabled: true,
    maxFileSize: 10 * 1024 * 1024, // 10MB
    allowedMimeTypes: ["image/jpeg", "image/png"],
  },
});

Additional Resources