Install Payload CMS

Ref: https://payloadcms.com/docs/getting-started/installation

Check current node version
[codesyntax lang=”bash”]

[/codesyntax]

Use node version 20.9.0+
Check available node version
[codesyntax lang=”bash”]

[/codesyntax]

So use node stable 20.15.1
[codesyntax lang=”bash”]

[/codesyntax]

Create a new dir ‘PayloadCMS’
[codesyntax lang=”bash”]

[/codesyntax]
Install the Payload CMS (blank)
[codesyntax lang=”bash”]

[/codesyntax]

Launch the App
[codesyntax lang=”bash”]

[/codesyntax]

Open it on the browser: http://localhost:3000/
Because it’s blank, so it’ll display a message

404

This page could not be found.

Go to the admin page http://localhost:3000/admin
Note: Make sure the mongod service is already started. If not, pls start it
[codesyntax lang=”bash”]

[/codesyntax]

For the first/empty user, it’ll be redirected to http://localhost:3000/admin/create-first-user
with this form

So fill the form with your user.
for example:
email: advcha@yahoo.com
password: Admin@123

So the admin dashboard will be like this

You can add any new user and media

The Code
The config in src/payload.config.ts

Add Payload Visual Editor –> DO THIS ON THE PAYLOAD WEB TEMPLATE
Ref: https://www.npmjs.com/package/payload-visual-editor

Payload Web Template
The same steps:
[codesyntax lang=”bash”]

[/codesyntax]

Go to the dir ‘payload-web’ then run!
[codesyntax lang=”bash”]

[/codesyntax]

Open it in your browser: http://localhost:3000

The admin : http://localhost:3000/admin
For the first/empty user, it’ll be redirected to http://localhost:3000/admin/create-first-user
So fill the form with your user.
for example:
email: advcha@yahoo.com
password: Admin@123
Name: Admin

So it’ll be like this

We can generate the example content by clicking ‘Seed your database’ –> ONLY ONCE
on the admin dashboard http://localhost:3000/admin

So the homepage will be like this

 

Add Payload Visual Editor
Ref: https://www.npmjs.com/package/payload-visual-editor
Install
[codesyntax lang=”bash”]

[/codesyntax]
then modify the plugin config (NOT IN src/payload.config.ts BECAUSE IT’S ALREADY LINKED TO src/plugins/index.ts
like this:
[codesyntax lang=”javascript”]

[/codesyntax]

But when I opened http://localhost:3000/admin, it showed this error
Failed to compile
[codesyntax lang=”text”]

[/codesyntax]

it seems visual editor can’t work with payload cms version 3.x

INSTALL Payload CMS version 2
Ref: https://payloadcms.com/docs/v2/getting-started/installation
To find out the payload cms package for npx, pls see https://www.npmjs.com/package/create-payload-app?activeTab=versions
actually there is no the package written for 2.x but there is a another package not 3.x. it’s 1.1.0. So use this
[codesyntax lang=”bash”]

[/codesyntax]

note: this is actually payload cms version 2. you can see it in the dependencies in  package.json file
[codesyntax lang=”javascript”]

[/codesyntax]

then go to the dir and run!
Note: don’t forget to start mongod service if it’s not a;ready started!
sudo service mongod start
if you need pnpm instead of npm, install it like this
npm install -g pnpm

[codesyntax lang=”bash”]

[/codesyntax]

We can generate the example content by clicking ‘Seed your database’ –> ONLY ONCE
on the admin dashboard http://localhost:3000/admin

Add Payload Visual Editor
Ref: https://www.npmjs.com/package/payload-visual-editor
[codesyntax lang=”bash”]

[/codesyntax]

modify src/payload/payload.config.ts
[codesyntax lang=”javascript”]

[/codesyntax]
note: can’t use [COLLECTION_SLUG] and [GLOBAL_SLUG] because they are defined. So add ‘pages’ and ‘posts’ (probably ‘projects’ as well)
but the previewUrl() still show 404 on the admin visual editor