
Product
Socket for Asana Is Now Available
Create and manage Asana tasks directly from Socket alerts, with manual task creation, automated ticketing rules, and two-way sync.
@rnaga/wp-node-cli
Advanced tools
π **[View Full Documentation at rnaga.github.io/wp-node β](https://rnaga.github.io/wp-node/)**
π View Full Documentation at rnaga.github.io/wp-node β
WP-Node is a Node.js project written in TypeScript that mirrors the WordPress database schema and functionality. It enables developers to build scalable, modern backends on top of existing WordPress data.
Key benefits include:
posts, users, terms, comments, etc.)Here's an example of how to initialize WP-Node app and access WordPress post:
import Application from "@rnaga/wp-node/application";
(async () => {
// Initialize WP-Node application
const wp = await Application.getContext();
// Fetch a post with ID 1
const post = await wp.utils.query.posts((query) => {
query.where("ID", 1);
});
process.exit(0);
})();
PostUtil, TermUtil, and MetaUtil, enabling clean separation of concerns and easier testingdo_action, apply_filters), and supports implementation as async-compatible functionsWP-Node is ideal for scenarios where you need direct access to WordPress database without relying on the full WordPress stack. Example use cases include:
>=22.0.0nvm command installed on your local machine.To spin up a sample environment with WordPress and database in Docker:
docker network inspect wpnet >/dev/null 2>&1 || docker network create wpnet && \
docker run -d --name wpdb --network wpnet -p 33306:3306 \
-e MYSQL_ROOT_PASSWORD=example \
-e MYSQL_DATABASE=wordpress \
-e MYSQL_USER=wp \
-e MYSQL_PASSWORD=wp \
mariadb && \
docker run -d --name wp --network wpnet -p 8080:80 \
-e WORDPRESS_DB_HOST=wpdb:3306 \
-e WORDPRESS_DB_USER=wp \
-e WORDPRESS_DB_PASSWORD=wp \
-e WORDPRESS_DB_NAME=wordpress \
wordpress
Visit http://localhost:8080 in your browser to complete the WordPress setup.
To get started, create a new folder for your project. This folder will serve as the root directory for your WP-Node application.
mkdir wp-node
cd wp-node
Then, run the command to initialize the project and follow the prompts:
npx @rnaga/wp-node-cli -- init
β Enter your database hostname: Β· localhost
β Enter your database port: Β· 33306
β Enter your database username: Β· wp
β Enter your database password: Β· **
β Enter your database name: Β· wordpress
β Is it a multi-site? Β· No
β Enter your static assets path: Β· public
After initialization, your project will look like this:
./
βββ _wp
βΒ Β βββ config
βΒ Β βΒ Β βββ index.d.ts
βΒ Β βΒ Β βββ wp.json
βΒ Β βββ settings.ts
βββ .env
βββ index.ts
βββ package-lock.json
βββ package.json
βββ tsconfig.json
Key files
_wp/config/wp.json: Holds configuration for WP-Node such as public path and multisite info. This file is imported by settings.ts._wp/settings.ts: Initializes the WP-Node Context, including config, database access and hooks.index.ts: The main entry point for your WP-Node app. A basic sample is provided..env: Stores sensitive environment variables, including your database credentials and other configuration values required at runtime.Once the config is initialized, run the app using:
mvn use 22
npx ts-node ./index.ts
If everything is working correctly, youβll see SQL output like:
select * from `wp_posts` as `posts_5` where `posts_5`.`ID` = 1
[
{
ID: 1,
post_author: 1,
post_title: 'Hello world!',
...
}
]
WP-Node CLI provides a convenient way to interact with WordPress data without writing any code.
To query a post (e.g. ID = 1), run:
npx @rnaga/wp-node-cli -- post get 1 -Z table -F ID,post_title,post_type
ββββββββββββββ¬βββββββββββββββββ
β (index) β Values β
ββββββββββββββΌβββββββββββββββββ€
β ID β 1 β
β post_title β 'Hello world!' β
β post_type β 'post' β
ββββββββββββββ΄βββββββββββββββββ
To view all available CLI commands, run:
npx @rnaga/wp-node-cli -- -h
output:
Usage: <command> <subcommand> [options]
Commands:
blog Blog commands
comment Comment commands
config Generate WP config files
init Initialize WP with Node. (Generate wp.json and install dependencies)
install Initialize a new blog and create a user
meta Meta commands (post, comment, blog, term, user, site)
option Options commands
post Post commands
repl Start a REPL
role Role commands
site Site commands
term Term commands
user User commands
Example:
@command("page", { description: "Page commands" })
export class PageCli extends Cli {
@subcommand("list", { description: "List pages" })
async list() {
const context = await Application.getContext();
const posts = await context.postUtil.findByType("page");
console.log(posts);
}
}
WP-Node uses a custom @component() decorator to support DI scopes:
@component({ scope: Scope.Transient })
export class Post {
constructor(
public meta: Meta,
private logger: Logger,
private queryUtil: QueryUtil,
...
) {}
}
apply_filters)do_action equivalent)WP-Node Core is designed specifically to interact with the WordPress database. It does not support traditional WordPress features such as:
Its scope is intentionally limited to providing a type-safe, programmatic interface to WordPress data β not replicating the full behavior of the WordPress runtime.
Feel free to fork, open issues, or suggest improvements. This project is in active development.
MIT License.
FAQs
π **[View Full Documentation at rnaga.github.io/wp-node β](https://rnaga.github.io/wp-node/)**
The npm package @rnaga/wp-node-cli receives a total of 18 weekly downloads. As such, @rnaga/wp-node-cli popularity was classified as not popular.
We found that @rnaga/wp-node-cli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.

Product
Create and manage Asana tasks directly from Socket alerts, with manual task creation, automated ticketing rules, and two-way sync.

Security News
Open VSX has removed three extension IDs from its malicious-extension list as the legitimate publishers they impersonated move to claim the names for themselves.

Product
Socketβs PHP and Composer support is now in Beta for all customers, with PHP reachability analysis generally available.