Last active
February 20, 2023 15:17
-
-
Save hdodov/c0ab8aeedd4a1722b9c6fae2baacb0c2 to your computer and use it in GitHub Desktop.
Payload CMS playground script for running code in a REPL fashion.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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