Skip to Content
Mock ServerPre-installed libraries

Using Pre-Installed Libraries

Code-based mock servers come with popular JavaScript libraries pre-installed. Load them with require in your scripts, with no installation step:

const _ = require('lodash'); const moment = require('moment'); const { faker } = require('@faker-js/faker'); mock.define('/test-libs', 'GET', (req, res) => { const randomUser = { id: faker.string.uuid(), name: faker.person.fullName(), email: faker.internet.email() }; res.json({ currentDate: moment().format(), activeUsers: _.filter([{ active: true }, { active: false }], { active: true }), randomUser: randomUser }); });

These libraries help you create rich, dynamic responses. Mock code runs without network access, so a library must be pre-installed or included in your apigit-mock/ folder. The supported libraries are:

  • @faker-js/faker (v9.9.0) - data generator
  • ajv (v8.17.1) - JSON schema validation
  • base64-js (v1.5.1) - Base64 encoding/decoding
  • body-parser (v1.20.3) - request body parsing
  • cookie-parser (v1.4.7) - cookie parsing
  • cors (v2.8.5) - Cross-Origin Resource Sharing middleware
  • jsonwebtoken (v9.0.2) - JWT creation and verification
  • lodash (v4.17.21) - general utility
  • moment (v2.30.1) - time and date handling
  • uuid (v11.0.3) - UUID generator
  • validator (v13.12.0) - validation helper

If another popular library would be useful to you, send a request to support@apigit.com.

Last updated on