Technologia

Node.js

JavaScript na serwerze. Event-driven, non-blocking I/O. Fundament nowoczesnego web backendu.

Czym jest Node.js?

Node.js to środowisko uruchomieniowe JavaScript zbudowane na silniku V8 Chrome. Pozwala uruchamiać JavaScript po stronie serwera. Node.js jest event-driven i non-blocking — obsługuje tysiące jednoczesnych połączeń na jednym wątku.

Node.js jest fundamentem ekosystemu: Next.js, Nest.js, Express, Fastify, Prisma, tRPC. Jeden język (TypeScript) na froncie i backendzie = shared types, szybszy development, mniejszy zespół.

Przykłady kodu

Express — REST API

Express + TypeScript import express from 'express'; import { z } from 'zod'; const app = express(); app.use(express.json()); const CreateUserSchema = z.object({ name: z.string().min(2), email: z.string().email(), age: z.number().min(18), }); app.post('/api/users', async (req, res) => { const result = CreateUserSchema.safeParse(req.body); if (!result.success) { return res.status(400).json(result.error.flatten()); } const user = await db.user.create({ data: result.data }); res.status(201).json(user); }); app.listen(3000);

Nest.js — modularny backend

Nest.js import { Controller, Get, Post, Body, Param } from '@nestjs/common'; @Controller('users') export class UsersController { constructor(private usersService: UsersService) {} @Get() async findAll() { return this.usersService.findAll(); } @Get(':id') async findOne(@Param('id') id: string) { return this.usersService.findOne(id); } @Post() async create(@Body() dto: CreateUserDto) { return this.usersService.create(dto); } }

Prisma ORM

Prisma Schema + Query // schema.prisma model User { id String @id @default(uuid()) name String email String @unique orders Order[] createdAt DateTime @default(now()) } // TypeScript query — full type safety const users = await prisma.user.findMany({ where: { orders: { some: { status: 'completed' } } }, include: { orders: { where: { status: 'completed' }, orderBy: { createdAt: 'desc' }, take: 5, }, }, });

WebSocket — real-time

Socket.io import { Server } from 'socket.io'; const io = new Server(server, { cors: { origin: '*' } }); io.on('connection', (socket) => { console.log('User connected:', socket.id); socket.on('join-room', (roomId: string) => { socket.join(roomId); socket.to(roomId).emit('user-joined', socket.id); }); socket.on('message', ({ roomId, text }) => { io.to(roomId).emit('message', { userId: socket.id, text, timestamp: Date.now(), }); }); });

Ocena kompetencji

Ekosystem (npm)
99%
I/O performance
90%
Real-time
95%
Full-stack
98%
CPU-intensive
40%
Łatwość nauki
85%

Co potrafi Node.js

REST / GraphQL API

Express, Fastify, Nest.js, tRPC. Middleware, validation, auth, rate limiting.

Full-stack (Next.js)

Server components, API routes, SSR/SSG, middleware. Jeden deploy = front + back.

Real-time

Socket.io, WebSockets, Server-Sent Events. Chat, notifications, live dashboards.

Microservices

Lekkie serwisy, message queues (BullMQ, RabbitMQ), event-driven architecture.

ORM & DB

Prisma, Drizzle, TypeORM, Knex. PostgreSQL, MongoDB, Redis. Migracje, seedy.

Serverless

Vercel Functions, AWS Lambda, Cloud Functions. Cold start ~100ms. Pay-per-invocation.

Kiedy wybrać Node.js?

Idealny gdy: budujesz web app (full-stack z Next.js), potrzebujesz real-time features, chcesz jeden język na froncie i backendzie, budujesz API dla SPA/mobile.

Nie najlepszy gdy: potrzebujesz heavy CPU computation (lepiej Go/Rust), budujesz ML pipeline (lepiej Python), potrzebujesz ekstremalnej wydajności (lepiej Go).