npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tanstack-setup

v1.0.0

Published

CLI tool to scaffold API call setup with Axios and Tanstack Query

Downloads

12

Readme

tanstack-setup

npm version license downloads

A CLI tool to scaffold API call setups for React projects using Axios and Tanstack Query. It generates a modular src/ directory structure with API configurations, an Axios instance, React Query hooks, and utility functions for local storage and query string building.


🚀 Quick Start

npx tanstack-setup init

Enter your API base URL, handle existing directories/files, and the CLI sets up everything automatically.


✨ Features

  • Interactive Setup: Prompts for API base URL to configure the Axios instance.
  • Modular Structure: Generates files in src/ with subdirectories (config/, hooks/, utils/).
  • Smart File Handling: Options to skip, overwrite, or merge existing directories/files.
  • Utility Functions: Includes buildQueryString, getItem, setItem, and more.
  • Type-Safe: Built with TypeScript support.
  • Dependencies Installed: Installs axios, @tanstack/react-query, sonner, and js-cookie.

🛠️ Installation

npx tanstack-setup init

No global install needed. Works in any Node.js project (Node 16+ recommended).


📦 Usage

  1. Run CLI:

    npx tanstack-setup init
  2. Enter API Base URL: Example: https://api.example.com/v1.

  3. Handle Existing Files/Directories:

    • Directories: Skip, Overwrite, or Merge (default).
    • Files: Skip (default) or Overwrite.
  4. Review Output: CLI creates the src/ structure and installs dependencies.


📁 Generated Project Structure

src/
├── config/
│   ├── api/
│   │   └── api.ts
│   └── instance/
│       └── instance.ts
├── hooks/
│   ├── useFetchData.ts
│   ├── usePostData.ts
│   ├── usePutData.ts
│   ├── usePatchData.ts
│   └── useDeleteData.ts
├── utils/
│   └── storage.ts

📄 Example

import useFetchData from '@/hooks/useFetchData';
import API from '@/config/api';

const UserList = () => {
  const { data, isLoading, error } = useFetchData({
    url: API.auth.login,
    params: { role: 'admin' },
  });

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <ul>
      {data?.map((user) => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
};

export default UserList;

🔧 Requirements

src/types/index.ts

export enum StorageEnum {
  Token = 'token',
}

export interface Result {
  statusCode: number;
  error: boolean;
  message?: string;
  data?: any;
}

useToast (Example with react-toastify)

import { toast as toastify } from 'react-toastify';

export const useToast = () => ({
  toast: ({ title, description, variant }) => {
    toastify(description, { type: variant === 'destructive' ? 'error' : 'success' });
  },
});

src/constants/data.ts

export const BASIC_AUTH_CREDENTIALS = {
  username: 'your-username',
  password: 'your-password',
};

📦 Dependencies

Installed automatically:

  • axios
  • @tanstack/react-query
  • sonner
  • js-cookie

If not, run:

npm install axios @tanstack/react-query sonner js-cookie

🧰 Troubleshooting

  • v is not defined: Fixed in v1.0.4.
  • Manual install failed: Try installing dependencies manually.
  • Missing utilities: Add StorageEnum, Result, useToast, BASIC_AUTH_CREDENTIALS.

🤝 Contributing

Contributions welcome!

git clone https://github.com/pavandeepkumar/api-setup
cd api-setup
git checkout -b feature/my-feature

Push and open a pull request.


📄 License

MIT License


📫 Contact

Author: Pavandeep
Email: [email protected]
GitHub: pavandeepkumar
npm: tanstack-setup