DEV Community

Cover image for Use over 140+ amazing ChatGPT prompts in 10 minutes πŸš€
pacholoamit
pacholoamit

Posted on

Use over 140+ amazing ChatGPT prompts in 10 minutes πŸš€

We're going to be exploring this amazing NodeJS library called chatgpt-prompts. This library allows you to use over 140+ amazing community built prompts compiled over at awesome-chatgpt-prompts instantly.

πŸš€ Quick Start!

If you are impatient person (like me!), here's a quick start on what the code would look like for a basic example but I recommend you follow along just to ensure that your (hopefully typescript) project gets set up correctly as this package is ESM-only.

import { ChatGPTAPI } from "chatgpt";
import { createChatGPTPrompt } from "chatgpt-prompts";

const run = async () => {
  const instance = new ChatGPTAPI({
    apiKey: "OPEN_AI_API_KEY",
  });

  const prompt = createChatGPTPrompt(instance);

  let res = await prompt.linuxTerminal("touch hello.txt");
  console.log(res.text);

  res = await prompt.linuxTerminal("echo hello world > hello.txt");
  console.log(res.text);

  res = await prompt.linuxTerminal("cat hello.txt");

  console.log(res.text);
};

run().catch((err) => console.log("Something went wrong"));

Enter fullscreen mode Exit fullscreen mode

πŸ’» Project Setup

This section details how we would set up our typescript & NodeJS project with the chatgpt and chatgpt-prompts package.

To start setting up our project let's create a directory to house all of the code for our project

mkdir chatgpt-app
cd chatgpt-app
Enter fullscreen mode Exit fullscreen mode

Now we have a directory, let's create a package.json file by running

npm init -y
Enter fullscreen mode Exit fullscreen mode

Now let's install all of our dependencies and dev dependencies

npm install --save-dev nodemon ts-node typescript 
npm install chatgpt chatgpt-prompts 
Enter fullscreen mode Exit fullscreen mode

Your package.json file should look something like this

{
  "name": "chatgpt-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "nodemon": "^2.0.20",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.5"
  }
}
Enter fullscreen mode Exit fullscreen mode

We're going to be making some absolutely important changes to our package.json file since chatgpt and chatgpt-prompts are ESM-only packages.

Modify your package.json so that it looks something like this

{
  "name": "chatgpt-app",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "type": "module",
  "scripts": {
    "start": "nodemon --ext js,ts,json,env --exec 'node --experimental-specifier-resolution=node --loader ts-node/esm' src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "nodemon": "^2.0.20",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.5"
  },
  "dependencies": {
    "chatgpt": "^4.1.1",
    "chatgpt-prompts": "^1.1.1"
  }
}
Enter fullscreen mode Exit fullscreen mode

Here were the changes that we've made for extra clarity:

  • We've changed the main field from index.js to dist/index.js
  • We've added the types field with a value of dist/index.d.ts
  • We've added the type field with a value of module; and finally
  • We've modified the start script to be really long.

After this is completed, we're going to set up our lengthy but absolutely necessary tsconfig.json file. Feel free to copy the one below

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "importHelpers": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "declaration": true,
    "alwaysStrict": true,
    "forceConsistentCasingInFileNames": true,
    "removeComments": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "strict": true,
    "noFallthroughCasesInSwitch": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "composite": true,
    "skipLibCheck": true,
    "noEmitHelpers": false,
    "outDir": "dist",
    "rootDir": "src",
    "baseUrl": "."
  },
  "include": ["src"],
  "exclude": ["dist", "node_modules"]
}
Enter fullscreen mode Exit fullscreen mode

Awesome! After that is set up, we're now going to be writing some actual code. Please run the commands below to create a src directory and an index.ts file.

mkdir src
cd src
touch index.ts
Enter fullscreen mode Exit fullscreen mode

Now we have created our index.ts file, let's actually write and run our code. Here's a code snippet to get you started

import { ChatGPTAPI } from "chatgpt";
import { createChatGPTPrompt } from "chatgpt-prompts";

const run = async () => {
  const instance = new ChatGPTAPI({
    apiKey: "OPEN_AI_API_KEY",
  });

  const prompt = createChatGPTPrompt(instance);

  let res = await prompt.linuxTerminal("touch hello.txt");
  console.log(res.text);

  res = await prompt.linuxTerminal("echo hello world > hello.txt");
  console.log(res.text);

  res = await prompt.linuxTerminal("cat hello.txt");

  console.log(res.text);
};

run().catch((err) => console.log("Something went wrong"));

Enter fullscreen mode Exit fullscreen mode

You should have an output similar to that one below

Success message

πŸ’― Congratulations

You now have access to over 140+ amazing prompts in NodeJS. I'd also like to credit the following people for the awesome work they've done:

Top comments (0)