Website Backend Development with Node.js (Koa)

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Showing 1 of 1 servicesAll 2065 services
Website Backend Development with Node.js (Koa)
Medium
from 1 week to 3 months
FAQ
Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Web Backend Development on Node.js (Koa)

Koa—minimalist framework from Express creators, reimagined for async/await. Where Express requires next() callbacks, Koa works through async/await and middleware stack executing "onion" principle: request passes middleware top-down, response—bottom-up.

Choose Koa when: need full freedom choosing libraries without framework opinions, but want proper async code handling unlike Express.

Middleware Pattern

import Koa from 'koa'
import Router from '@koa/router'

const app = new Koa()

// Logging middleware—wraps everything below
app.use(async (ctx, next) => {
  const start = Date.now()
  await next()  // executes everything else
  const ms = Date.now() - start
  console.log(`${ctx.method} ${ctx.url} - ${ctx.status} - ${ms}ms`)
})

// Error handling
app.use(async (ctx, next) => {
  try {
    await next()
  } catch (err) {
    ctx.status = err.statusCode || err.status || 500
    ctx.body = {
      error: process.env.NODE_ENV === 'production' ? 'Internal Server Error' : err.message
    }
  }
})

Principal difference from Express: in Koa after await next() you return to middleware with access to final response state. In Express impossible without hacks.

Routing

@koa/router—official router:

import Router from '@koa/router'
import bodyParser from '@koa/bodyparser'

const router = new Router({ prefix: '/api/v1' })

router.get('/products', authenticate, async (ctx) => {
  const { page = 1, limit = 20 } = ctx.query
  const offset = (page - 1) * limit

  const [items, total] = await Promise.all([
    db.query('SELECT * FROM products LIMIT $1 OFFSET $2', [limit, offset]),
    db.query('SELECT COUNT(*) FROM products')
  ])

  ctx.body = {
    data: items.rows,
    pagination: {
      page: Number(page),
      limit: Number(limit),
      total: Number(total.rows[0].count)
    }
  }
})

router.post('/products', authenticate, requireRole('admin'), async (ctx) => {
  const data = ctx.request.body
  const product = await ProductService.create(data)
  ctx.status = 201
  ctx.body = product
})

app.use(router.routes())
app.use(router.allowedMethods())

Validation Middleware

const validateBody = (schema) => {
  return async (ctx, next) => {
    try {
      ctx.request.body = await schema.validate(ctx.request.body)
      await next()
    } catch (err) {
      ctx.status = 422
      ctx.body = { error: 'Validation failed', details: err.details }
    }
  }
}

router.post('/products', validateBody(createProductSchema), async (ctx) => {
  // body already validated
})

Database Access

import { Pool } from 'pg'

const pool = new Pool({ connectionString: process.env.DATABASE_URL })

// Middleware to attach db to context
app.use(async (ctx, next) => {
  ctx.db = pool
  await next()
})

// Or as service
class ProductService {
  static async list(query) {
    const result = await pool.query('SELECT * FROM products LIMIT $1', [query.limit])
    return result.rows
  }
}

Error Handling

class AppError extends Error {
  constructor(message, statusCode) {
    super(message)
    this.statusCode = statusCode
  }
}

app.use(async (ctx, next) => {
  try {
    await next()
  } catch (err) {
    if (err instanceof AppError) {
      ctx.status = err.statusCode
      ctx.body = { error: err.message }
    } else {
      ctx.status = 500
      ctx.body = { error: 'Internal server error' }
    }
  }
})

// Usage
if (!product) {
  throw new AppError('Product not found', 404)
}

Running Server

// index.js
const app = new Koa()

// Middleware stack
app.use(errorHandler)
app.use(bodyParser())
app.use(router.routes())

app.listen(process.env.PORT || 3000, () => {
  console.log('Server running on port', process.env.PORT || 3000)
})

Timeline

Basic setup with routing and middleware—1 day. Database integration, authentication—2–3 days. Full API with validation, testing—1 week.

Koa suits small teams, greenfield projects, or when you prefer composing libraries over framework conventions.