NID (Node ID)
The NID is the unique number Drupal gives each node. It is the number in /node/42, and it stays the same when a URL alias is added or changed.
A NID, or node ID, is the unique number Drupal assigns to each node: the article, page or other content item you create. It is the identifier of the node entity, stored in the nid column, and it is the number in the system path /node/42. Drupal uses it to find the node, whatever URL alias the page also has.
How it works in Drupal 11
The Node class maps its entity keys as follows:
nid: the ID of the node.vid: the ID of a revision.uuid: a universally unique identifier.type: the bundle, in other words the content type.uid: the owner, which is the author's UID.
The data sits in the node, node_field_data, node_revision and node_field_revision tables. The link templates for a single node contain the number: the page is at /node/{node}, the edit form at /node/{node}/edit, deletion at /node/{node}/delete and the revision list at /node/{node}/revisions. The revision routes only accept digits for the node part.
The NID identifies the node, while the VID identifies one saved revision of it. Saving an edit does not give the node a new NID.
NID and URL aliases
Most public pages are not shown at /node/42 but at an alias such as /about-us. The Drupal User Guide describes the same idea with its node/7 example. The alias path processor looks up the alias for outgoing links and converts an incoming alias to its system path. When a path has no alias, the alias manager returns it unchanged. The NID is therefore the stable part; the alias is the friendly label on top.
Example: look up and load a node
Find a NID from the command line by searching titles with Drush. Table prefixes must be added by hand, and the example assumes none:
drush sql:query "SELECT nid, title FROM node_field_data WHERE title LIKE '%pricing%'"
In custom code, load the node by its number. The method returns NULL when no entity has that ID:
$node = \Drupal\node\Entity\Node::load(42);
if ($node) {
$title = $node->getTitle();
}
Common mistakes
- Hard-coding NIDs in code or exported configuration. The NID belongs to one database. Use the UUID or the alias when a reference has to survive a move between environments.
- Confusing NID and VID. A link to
/node/42shows node 42, not revision 42. - Confusing a node ID with a user ID.
/node/5and/user/5are different entities. - Forgetting the NULL case. A deleted node leaves a dead number behind in notes and links. Check the result of
load().
For marketing and content teams
When a developer asks for the NID of a page, open its edit form and read the number from the address: /node/42/edit means NID 42. An alias is a separate record that someone can edit, while the system path /node/42 always points at the same node. That makes it a reliable way to reference a page in a bug report or a spreadsheet of content to audit. For public links in emails or ads, use the alias, since it is readable.