Quick Start Guide
Get started with XyPriss in a few simple steps.
Installation
npm install xypriss
# or
yarn add xypriss
For additional security features:
npm install 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
npm run 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.json({ 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.json({ 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.json({ 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.json({ users: [] });
});
app.post("/api/users", (req, res) => {
res.json({ 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();
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
- Routing Guide - Configure routes, parameters, and middleware
- Security Guide - Implement CORS, CSRF, and rate limiting
- File Upload Guide - Handle file uploads
- Configuration Reference - Complete configuration options
- API Reference - Full API documentation
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
- Documentation - Complete guides
- Examples - Code examples
- GitHub Issues - Report bugs
- GitHub Discussions - Community support