Non-tech founder’s guide to choosing the right software development partner Download Ebook
Home>Blog>How quickly and easily run a local server with fake api data (mocks)?

How quickly and easily run a local server with fake api data (mocks)?

Sometimes you need to develop a frontend part of a project without a ready-made api, knowing only its structure. In this case, using json-schema-faker, you can generate fake data (mocks) and deploy it to your local server.

Firstly u will need to install json-schema-faker package


yarn add json-schema-faker

Then open the package.json file and add scripts with the following


// ...

"scripts": {

  // ...

  "start-mockapi": "json-server --watch ./mocks/api/db.json --port 3001",

  "generate-mock-data": "node ./generateMockData",

}

After installation, you will need to describe the structure in ./mocks/dataSchema.js of future mocks. You can find more information here.


const schema = {

  reports: {

    type: 'array',

    minItems: 5,

    maxItems: 10,

    items: {

      id: {

        type: 'integer',

        unique: true,

        minimum: 1,

        maximum: 1000,

      },

      title: {

        enum: ['production', 'azure data', 'azure data 2'],

      },

      logo: 'https://picsum.photos/200'

    },

  },

}



module.exports = schema;

Copy paste script for generating mock data from here in ./generateMockData.js and run the following


yarn generate-mock-data && yarn start-mockapi

Discover More Reads

Recent Projects

We take pride in creating applications that drive growth and evolution, from niche startups to international companies.

Do you have a tech idea?

Let’s talk!

By submitting this form, you agree with JetRockets’ Privacy Policy

If you prefer email, write to us at hello@jetrockets.com