How to solve coding issues using ChatGPT

Read Time:2 Minute, 24 Second

Simply put, I need to check if a node package is installed in runtime. The reason is that I’m building a new toolkit ZenStack, for building secure CRUD apps with Next.js + Typescript. Since it is built above Prisma, when running the CLI provided by ZenStack, it must check whether Prisma has already been installed. Otherwise, it would prompt the user to install Prisma first.

Let’s try to ask ChatGPT directly:

How to solve coding issues using ChatGPT

Cool! The answer looks compelling. Problem solved!

It does work, but it brings one side effect. In my CLI project, I use async-exit-hook to handle uncaught errors like the below:

Enter fullscreen mode Exit fullscreen mode

After the require(’prisma’) is executed successfully, the uncaughtExceptionHandler would never be triggered.

It looks like some code is running when Prisma is imported. I’m not sure whether Prisma provides any flag to control it; even if it does, it still doesn’t sound like a clean solution to me because it is like Pandora’s box. You won’t know what gets executed.

The most direct way to avoid a side effect is to use a separate process. So how would you do that if the job is assigned to you? I will use the npm command. So let’s ask the omniscient again:


This looks like a clean solution to me.

As good developers, we should always try to think further. What if the npm command is not installed or is broken? If we know how npm finds the module, we could do that ourselves.

Let’s ask again:


As the npm command obviously won’t execute any code for the package, it does find the name and version as the answer specified:

It will display the names and versions of all the installed package

So, where does it get the version information? Of course, from package.json file. Actually, you can easily verify it by creating dummy-package folder under node_modules, and then creating the package.json file with the below content:

Enter fullscreen mode Exit fullscreen mode

Then after running npm list --depth=0 dummy-package , you could see the package info:

Enter fullscreen mode Exit fullscreen mode

Therefore, instead of requiring the module like the original solution, we could change it to require the package.json file like:

Enter fullscreen mode Exit fullscreen mode

Not only does it get rid of the side effect, but also you could get more information for that package, like version, etc.

Anyway, you can see ChatGPT really could help us a lot, even writing the code for us, but it is us who actually think and resolve the issue thoroughly. Coming to the thought that AI would replace developers, I think Google should worry about that rather than us. 😉


CyberSEO Pro - OpenAI GPT-3 autoblogging and content curation plugin for WordPress

Tag Cloud

Java Java Logical Programs OTP Generation in Java python Recursion youtube video ASCII Upper and Lower Case blockchain javascript graph learn to code software development Successful Software Engineers breadth first search Java Array Programs Java Programs Uncategorized android ios programming kotlin web-development django data sql cybersecurity database swiftui serverless aws swift rust react background-position gradients loader mask grid nth-child pseudo elements indieweb WordPress Print Array without brackets C++ factorial Java String Programs Final Keyword Static Variable Axie Infinity Cryptokitties NFT games tool inserting MISC Tips Codes python code python projects python3 system info python project Bigginers How to Do Integrations Payment Gateways PHP checkout page in php Implement stripe payment gateway in Step by step in PHP integrate stripe gatway in php mysql payment gateway integration in php step by step payment gateway integration in php step by step with source code payment gateway integration in website PHP Integrate Stripe Payment Gateway Tutorial PHP shopping cart checkout code shopping cart in php stripe php checkout PHP/MySQL/JSON best international payment gateway does google pay accept international payments how to accept international payments in india paytm payment gateway razorpay codeigniter github razorpay custom checkout github razorpay get payment details razorpay integration in codeigniter github razorpay international payments Razorpay payment gateway integration in CodeIgniter razorpay payment gateway integration in php code Razorpay payment gateway integration with PHP and CodeIgniter Razorpay payment gateway setup in CodeIgniter Library & Frameworks Tips & Tricks UI/UX & Front-end coding birds online html code for google sign in login with google account in PHP login with google account using javascript login with google account using javascript codeigniter login with google account using php login with google account using php source code
Drag and Drop File using Javascript Previous post Drag and Drop File using Javascript
How to Write an Awesome Readme Next post How to Write an Awesome Readme

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.