Groups as permission scopes

Every CoValue has an owner, which can be a Group or an Account.

You can use a Group to grant access to a CoValue to multiple users. These users can have different roles, such as "writer", "reader" or "admin".

CoValues owned by an Account can only be accessed by that Account. Additional collaborators cannot be added, and the ownership cannot be transferred to another Account. This makes account ownership very rigid.

Creating a Group for every new CoValue is a best practice, even if the Group only has a single user in it (this is the default behavior when creating a CoValue with no explicit owner).

While creating CoValues with Accounts as owners is still technically possible for backwards compatibility, it will be removed in a future release.

Creating a Group

Here's how you can create a Group.

import { class Group
@categoryIdentity & Permissions
Group
} from "jazz-tools";
const const group: Groupgroup = class Group
@categoryIdentity & Permissions
Group
.
Group.create<Group>(this: CoValueClass<Group>, options?: {
    owner: Account;
} | Account): Group
create
();

The Group itself is a CoValue, and whoever owns it is the initial admin.

You typically add members using public sharing or invites. But if you already know their ID, you can add them directly (see below).

Adding group members by ID

You can add group members by ID by using Account.load and Group.addMember.

import { class Group
@categoryIdentity & Permissions
Group
, import coco } from "jazz-tools";
const const group: Groupgroup = class Group
@categoryIdentity & Permissions
Group
.
Group.create<Group>(this: CoValueClass<Group>, options?: {
    owner: Account;
} | Account): Group
create
();
const
const bob: ({
    readonly profile: ({
        readonly name: string;
        readonly inbox?: string | undefined;
        readonly inboxInvite?: string | undefined;
    } & CoMap) | null;
    readonly root: ({
        readonly [x: string]: any;
    } & CoMap) | null;
} & Account) | CoMapLikeLoaded<...> | null
bob
= await import coco.
account<BaseAccountShape>(shape?: BaseAccountShape | undefined): co.Account<BaseAccountShape>
export account
Defines a collaborative account schema for Jazz applications. Creates an account schema that represents a user account with profile and root data. Accounts are the primary way to identify and manage users in Jazz applications.
@templateShape - The shape of the account schema extending BaseAccountShape@paramshape - The account schema shape. Defaults to a basic profile with name, inbox, and inboxInvite fields, plus an empty root object.@example```typescript // Basic account with default profile const BasicAccount = co.account(); // Custom account with specific profile and root structure const JazzAccount = co.account({ profile: co.profile({ name: z.string(), avatar: z.optional(z.string()), }), root: co.map({ organizations: co.list(Organization), draftOrganization: DraftOrganization, }), }).withMigration(async (account) => { // Migration logic for existing accounts if (!account.$jazz.has("profile")) { const group = Group.create(); account.$jazz.set("profile", co.profile().create( { name: getRandomUsername() }, group )); group.addMember("everyone", "reader"); } }); ```
account
().
AccountSchema<BaseAccountShape>.load: <ResolveQuery<co.Account<BaseAccountShape>>>(id: string, options?: {
    loadAs?: Account | AnonymousJazzAgent;
    resolve?: ({
        ...;
    } & {
        ...;
    }) | ... 1 more ... | undefined;
} | undefined) => Promise<...>
load
(const bobsID: "co_z123"bobsID);
if (
const bob: ({
    readonly profile: ({
        readonly name: string;
        readonly inbox?: string | undefined;
        readonly inboxInvite?: string | undefined;
    } & CoMap) | null;
    readonly root: ({
        readonly [x: string]: any;
    } & CoMap) | null;
} & Account) | CoMapLikeLoaded<...> | null
bob
) {
const group: Groupgroup.Group.addMember(member: Account, role: AccountRole): void (+3 overloads)addMember(
const bob: ({
    readonly profile: ({
        readonly name: string;
        readonly inbox?: string | undefined;
        readonly inboxInvite?: string | undefined;
    } & CoMap) | null;
    readonly root: ({
        readonly [x: string]: any;
    } & CoMap) | null;
} & Account) | CoMapLikeLoaded<...>
bob
, "writer");
}

Note:

  • Both Account.load(id) and co.account().load(id) do the same thing — they load an account from its ID.
import { type ID<T> = string
IDs are unique identifiers for `CoValue`s. Can be used with a type argument to refer to a specific `CoValue` type.
@example```ts type AccountID = ID<Account>; ```@categoryCoValues
ID
, class Account
@categoryIdentity & Permissions
Account
, import coco } from "jazz-tools";
const const bob: Account | nullbob = await class Account
@categoryIdentity & Permissions
Account
.
Account.load<Account, true>(this: CoValueClass<...>, id: ID<Account>, options?: {
    resolve?: RefsToResolve<Account, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
Load an `Account`
@categorySubscription & Loading@deprecatedUse `co.account(...).load` instead.
load
(const bobsID: "co_z123"bobsID);
// Or: const bob = await co.account().load(bobsID); if (const bob: Account | nullbob) { const group: Groupgroup.Group.addMember(member: Account, role: AccountRole): void (+3 overloads)addMember(const bob: Accountbob, "writer"); }

Changing a member's role

To change a member's role, use the addMember method.

const group: Groupgroup.Group.addMember(member: Account, role: AccountRole): void (+3 overloads)addMember(
const bob: Account | ({
    readonly [x: string]: any;
} & Account)
bob
, "reader");

Bob just went from a writer to a reader.

Note: only admins can change a member's role.

Removing a member

To remove a member, use the removeMember method.

const group: Groupgroup.Group.removeMember(member: Everyone | Account): void (+1 overload)removeMember(
const bob: Account | ({
    readonly [x: string]: any;
} & Account)
bob
);

Rules:

  • All roles can remove themselves.
  • Only admins can remove other users.
  • An admin cannot remove other admins.
  • As an admin, you cannot remove yourself if you are the only admin in the Group, because there has to be at least one admin present.

Getting the Group of an existing CoValue

You can get the group of an existing CoValue by using coValue.$jazz.owner.

const const group: undefinedgroup = 
const existingCoValue: Account | ({
    readonly [x: string]: any;
} & Account)
existingCoValue
.
Account.$jazz: AccountJazzApi<Account> | AccountJazzApi<{
    readonly [x: string]: any;
} & Account>
Jazz methods for Accounts are inside this property. This allows Accounts to be used as plain objects while still having access to Jazz methods.
$jazz
.AccountJazzApi<A extends Account>.owner: undefined
Accounts have no owner. They can be accessed by everyone.
owner
;
const
const newValue: {
    readonly color: string;
} & CoMap
newValue
=
const MyCoMap: co.Map<{
    color: z.z.ZodString;
}, unknown, Account | Group>
MyCoMap
.
CoMapSchema<{ color: ZodString; }, unknown, Account | Group>.create(init: {
    color: string;
}, options?: {
    owner?: Group;
    unique?: CoValueUniqueness["uniqueness"];
} | Group): {
    ...;
} & CoMap (+1 overload)
create
(
{ color: stringcolor: "red"}, { owner?: Group | undefinedowner: const group: undefinedgroup } );

Checking the permissions

You can check the permissions of an account on a CoValue by using the canRead, canWrite and canAdmin methods.

const 
const value: {
    readonly color: string;
} & CoMap
value
= await
const MyCoMap: co.Map<{
    color: z.z.ZodString;
}, unknown, Account | Group>
MyCoMap
.
CoMapSchema<{ color: ZodString; }, unknown, Account | Group>.create(init: {
    color: string;
}, options?: {
    owner?: Group;
    unique?: CoValueUniqueness["uniqueness"];
} | Group): {
    ...;
} & CoMap (+1 overload)
create
({ color: stringcolor: "red"})
const const me: AccountInstanceCoValuesNullable<BaseAccountShape>me = await import coco.
account<BaseAccountShape>(shape?: BaseAccountShape | undefined): co.Account<BaseAccountShape>
export account
Defines a collaborative account schema for Jazz applications. Creates an account schema that represents a user account with profile and root data. Accounts are the primary way to identify and manage users in Jazz applications.
@templateShape - The shape of the account schema extending BaseAccountShape@paramshape - The account schema shape. Defaults to a basic profile with name, inbox, and inboxInvite fields, plus an empty root object.@example```typescript // Basic account with default profile const BasicAccount = co.account(); // Custom account with specific profile and root structure const JazzAccount = co.account({ profile: co.profile({ name: z.string(), avatar: z.optional(z.string()), }), root: co.map({ organizations: co.list(Organization), draftOrganization: DraftOrganization, }), }).withMigration(async (account) => { // Migration logic for existing accounts if (!account.$jazz.has("profile")) { const group = Group.create(); account.$jazz.set("profile", co.profile().create( { name: getRandomUsername() }, group )); group.addMember("everyone", "reader"); } }); ```
account
().AccountSchema<BaseAccountShape>.getMe: () => AccountInstanceCoValuesNullable<BaseAccountShape>getMe();
if (const me: AccountInstanceCoValuesNullable<BaseAccountShape>me.Account.canAdmin(value: CoValue): booleancanAdmin(
const value: {
    readonly color: string;
} & CoMap
value
)) {
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
("I can share value with others");
} else if (const me: AccountInstanceCoValuesNullable<BaseAccountShape>me.Account.canWrite(value: CoValue): booleancanWrite(
const value: {
    readonly color: string;
} & CoMap
value
)) {
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
("I can edit value");
} else if (const me: AccountInstanceCoValuesNullable<BaseAccountShape>me.Account.canRead(value: CoValue): booleancanRead(
const value: {
    readonly color: string;
} & CoMap
value
)) {
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
("I can view value");
} else { var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
("I cannot access value");
}

To check the permissions of another account, you need to load it first:

const 
const value: {
    readonly color: string;
} & CoMap
value
= await
const MyCoMap: co.Map<{
    color: z.z.ZodString;
}, unknown, Account | Group>
MyCoMap
.
CoMapSchema<{ color: ZodString; }, unknown, Account | Group>.create(init: {
    color: string;
}, options?: {
    owner?: Group;
    unique?: CoValueUniqueness["uniqueness"];
} | Group): {
    ...;
} & CoMap (+1 overload)
create
({ color: stringcolor: "red"})
const
const bob: ({
    readonly profile: ({
        readonly name: string;
        readonly inbox?: string | undefined;
        readonly inboxInvite?: string | undefined;
    } & CoMap) | null;
    readonly root: ({
        readonly [x: string]: any;
    } & CoMap) | null;
} & Account) | CoMapLikeLoaded<...> | null
bob
= await import coco.
account<BaseAccountShape>(shape?: BaseAccountShape | undefined): co.Account<BaseAccountShape>
export account
Defines a collaborative account schema for Jazz applications. Creates an account schema that represents a user account with profile and root data. Accounts are the primary way to identify and manage users in Jazz applications.
@templateShape - The shape of the account schema extending BaseAccountShape@paramshape - The account schema shape. Defaults to a basic profile with name, inbox, and inboxInvite fields, plus an empty root object.@example```typescript // Basic account with default profile const BasicAccount = co.account(); // Custom account with specific profile and root structure const JazzAccount = co.account({ profile: co.profile({ name: z.string(), avatar: z.optional(z.string()), }), root: co.map({ organizations: co.list(Organization), draftOrganization: DraftOrganization, }), }).withMigration(async (account) => { // Migration logic for existing accounts if (!account.$jazz.has("profile")) { const group = Group.create(); account.$jazz.set("profile", co.profile().create( { name: getRandomUsername() }, group )); group.addMember("everyone", "reader"); } }); ```
account
().
AccountSchema<BaseAccountShape>.load: <ResolveQuery<co.Account<BaseAccountShape>>>(id: string, options?: {
    loadAs?: Account | AnonymousJazzAgent;
    resolve?: ({
        ...;
    } & {
        ...;
    }) | ... 1 more ... | undefined;
} | undefined) => Promise<...>
load
(const accountID: stringaccountID);
if (
const bob: ({
    readonly profile: ({
        readonly name: string;
        readonly inbox?: string | undefined;
        readonly inboxInvite?: string | undefined;
    } & CoMap) | null;
    readonly root: ({
        readonly [x: string]: any;
    } & CoMap) | null;
} & Account) | CoMapLikeLoaded<...> | null
bob
) {
if (
const bob: ({
    readonly profile: ({
        readonly name: string;
        readonly inbox?: string | undefined;
        readonly inboxInvite?: string | undefined;
    } & CoMap) | null;
    readonly root: ({
        readonly [x: string]: any;
    } & CoMap) | null;
} & Account) | CoMapLikeLoaded<...>
bob
.Account.canAdmin(value: CoValue): booleancanAdmin(
const value: {
    readonly color: string;
} & CoMap
value
)) {
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
("Bob can share value with others");
} else if (
const bob: ({
    readonly profile: ({
        readonly name: string;
        readonly inbox?: string | undefined;
        readonly inboxInvite?: string | undefined;
    } & CoMap) | null;
    readonly root: ({
        readonly [x: string]: any;
    } & CoMap) | null;
} & Account) | CoMapLikeLoaded<...>
bob
.Account.canWrite(value: CoValue): booleancanWrite(
const value: {
    readonly color: string;
} & CoMap
value
)) {
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
("Bob can edit value");
} else if (
const bob: ({
    readonly profile: ({
        readonly name: string;
        readonly inbox?: string | undefined;
        readonly inboxInvite?: string | undefined;
    } & CoMap) | null;
    readonly root: ({
        readonly [x: string]: any;
    } & CoMap) | null;
} & Account) | CoMapLikeLoaded<...>
bob
.Account.canRead(value: CoValue): booleancanRead(
const value: {
    readonly color: string;
} & CoMap
value
)) {
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
("Bob can view value");
} else { var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
("Bob cannot access value");
} }