Integrate the OpenAI library, set up your environment, and then execute the code.
Step 1. Set up your environment.
- Install Node.js: If you don't have it, download and install Node.js from the official website.
- Create a project folder: Create a new folder for your project and open it in VS Code.
- Initialize a Node.js project: Open the terminal in VS Code and run npm init -y to create a package.json file.
If Error: Follow these steps, highlighted or skip these steps
The error "File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system" means your PowerShell execution policy is set to restrict script execution. To fix this, you need to temporarily change the execution policy to allow scripts to run, then change it back to a more restrictive setting for security.
Here's how to resolve it.
- Open PowerShell as Administrator: Right-click the PowerShell icon and select "Run as administrator".
- Check the current execution policy: Type Get-ExecutionPolicy and press Enter. If the result is Restricted, you need to change it.
- Change the execution policy: Type Set-ExecutionPolicy RemoteSigned -Scope CurrentUser and press Enter. This allows you to run scripts signed by a trusted publisher or scripts created locally.
- Verify the change: Type Get-ExecutionPolicy again and confirm that the execution policy is now RemoteSigned.
- Run the npm command: Try running your npm command again (e.g., npm install).
- (Optional) Revert the execution policy: Once you're done, it's a good practice to revert to a more restrictive policy like Restricted or AllSigned. You can do this by typing Set-ExecutionPolicy Restricted -Scope CurrentUser and pressing Enter, according to Stack Overflow.
If No Error, continue these steps.
- Install the OpenAI library: Run npm install openai in the terminal to install the necessary library.
- Install dotenv (optional but recommended): Install the dotenv package to manage your API key securely: npm install dotenv.
- Create an API key: Get your OpenAI API key from the OpenAI platform.



Join the conversation! Your thoughts help the community grow.