Get Started with cnsh

Here's a step-by-step guide to get you started with `cnsh`:

1. Install cnsh

Install `cnsh` globally using npm:

npm install -g cnsh --verbose

2. Add or Remove Packages

Use the following commands to add or remove packages:

cnsh add [package]
cnsh remove [package]
cnsh add -g [package]
cnsh remove -g [package]

3. Install Dependencies

To install all dependencies listed in your `package.json`, use:

cnsh install

4. Using Packages in Your Project

Here’s how you can use an installed package in your project:

async function fetchData() {
    try {
        const axios = await import('./cnsh_lib/axios/package/dist/esm/axios.min.js');
        const response = await axios.default.get('https://jsonplaceholder.typicode.com/posts/1');
        console.log('Data fetched:', response.data);
    } catch (error) {
        console.error('Error fetching data:', error);
    }
}

fetchData();

5. Troubleshooting

If you encounter any issues, check the common problems and solutions below:

  • Issue: ✖ Failed to install {pkg}: Downloaded tarball is too small, indicating a possible issue.
    Solution: This error is commonly encountered with small packages, but it can also indicate that the tarball downloaded is corrupted. Try reinstalling the package or check the package source for issues.
  • Issue: ✖ Failed to install {pkg}: Failed to fetch package metadata: Request failed with status code 404.
    Solution: This error means the package you are trying to install does not exist. Verify the package name and try again.
  • Issue: ✖ Failed to install {pkg}: Failed to fetch package metadata:
    Solution: This usually indicates a Wi-Fi connection issue. Check your internet connection and try again.