Skip to content

Instantly share code, notes, and snippets.

@hdodov
Last active February 20, 2023 15:17
Show Gist options
  • Save hdodov/c0ab8aeedd4a1722b9c6fae2baacb0c2 to your computer and use it in GitHub Desktop.
Save hdodov/c0ab8aeedd4a1722b9c6fae2baacb0c2 to your computer and use it in GitHub Desktop.
Payload CMS playground script for running code in a REPL fashion.
// NOTE: This file must be in the `src` folder, i.e. `src/repl.ts`.
/**
* Playground script that can be used in a REPL fashion.
* Just `npm run repl` and Payload will run in a minimal, local API mode.
* @see https://payloadcms.com/docs/local-api/overview#local-api
*/
import payload from "payload";
import dotenv from "dotenv";
process.chdir(__dirname);
dotenv.config({
path: "../.env",
});
(async () => {
await payload.init({
secret: process.env.PAYLOAD_SECRET,
mongoURL: process.env.MONGODB_URI,
local: true,
});
/**
* Add code below…
*/
const result = await payload.find({
collection: "users",
});
console.log(result);
})();
{
"scripts": {
"repl": "nodemon --exec ts-node src/repl.ts"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment