//-// From {@link PubSub#getSnapshots}://-pubsub.getSnapshots((err,snapshots)=>{// `snapshots` is an array of Snapshot objects.});//-// From {@link PubSub#getSnapshotsStream}://-pubsub.getSnapshotsStream().on('error',console.error).on('data',(snapshot)=>{// `snapshot` is a Snapshot object.});//-// From {@link PubSub#snapshot}://-constsnapshot=pubsub.snapshot('my-snapshot');// snapshot is a Snapshot object.//-// Create a snapshot with {module:pubsub/subscription#createSnapshot}://-constsubscription=pubsub.subscription('my-subscription');subscription.createSnapshot('my-snapshot',(err,snapshot)=>{if(!err){// `snapshot` is a Snapshot object.}});//-// Seek to your snapshot://-constsubscription=pubsub.subscription('my-subscription');subscription.seek('my-snapshot',(err)=>{if(err){// Error handling omitted.}});
constsubscription=pubsub.subscription('my-subscription');constsnapshot=subscription.snapshot('my-snapshot');constcallback=(err,snapshot,apiResponse)=>{if(!err){// The snapshot was created successfully.}};snapshot.create('my-snapshot',callback);//-// If the callback is omitted, we'll return a Promise.//-snapshot.create('my-snapshot').then((data)=>{constsnapshot=data[0];constapiResponse=data[1];});
snapshot.delete((err,apiResponse)=>{});//-// If the callback is omitted, we'll return a Promise.//-snapshot.delete().then((data)=>{constapiResponse=data[0];});
constsubscription=pubsub.subscription('my-subscription');constsnapshot=subscription.snapshot('my-snapshot');snapshot.seek((err,apiResponse)=>{});//-// If the callback is omitted, we'll return a Promise.//-snapshot.seek().then((data)=>{constapiResponse=data[0];});
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Class Snapshot (4.8.0)\n\nVersion latestkeyboard_arrow_down\n\n- [4.8.0 (latest)](/nodejs/docs/reference/pubsub/latest/pubsub/snapshot)\n- [4.4.0](/nodejs/docs/reference/pubsub/4.4.0/pubsub/snapshot)\n- [4.3.3](/nodejs/docs/reference/pubsub/4.3.3/pubsub/snapshot)\n- [4.1.1](/nodejs/docs/reference/pubsub/4.1.1/pubsub/snapshot)\n- [4.0.7](/nodejs/docs/reference/pubsub/4.0.7/pubsub/snapshot)\n- [3.7.5](/nodejs/docs/reference/pubsub/3.7.5/pubsub/snapshot)\n- [3.2.1](/nodejs/docs/reference/pubsub/3.2.1/pubsub/snapshot)\n- [3.1.1](/nodejs/docs/reference/pubsub/3.1.1/pubsub/snapshot)\n- [3.0.3](/nodejs/docs/reference/pubsub/3.0.3/pubsub/snapshot)\n- [2.18.3](/nodejs/docs/reference/pubsub/2.18.3/pubsub/snapshot)\n- [2.17.0](/nodejs/docs/reference/pubsub/2.17.0/pubsub/snapshot)\n- [2.16.6](/nodejs/docs/reference/pubsub/2.16.6/pubsub/snapshot)\n- [2.13.0](/nodejs/docs/reference/pubsub/2.13.0/pubsub/snapshot) \nA Snapshot object will give you access to your Cloud Pub/Sub snapshot.\n\nSnapshots are sometimes retrieved when using various methods:\n\n*** ** * ** ***\n\nSnapshots may be created with:\n\n- You can use snapshots to seek a subscription to a specific point in time.\n\n-\n\nPackage\n-------\n\n[@google-cloud/pubsub](../overview.html)\n\nExample\n-------\n\n\n //-\n // From {@link PubSub#getSnapshots}:\n //-\n pubsub.getSnapshots((err, snapshots) =\u003e {\n // `snapshots` is an array of Snapshot objects.\n });\n\n //-\n // From {@link PubSub#getSnapshotsStream}:\n //-\n pubsub.getSnapshotsStream()\n .on('error', console.error)\n .on('data', (snapshot) =\u003e {\n // `snapshot` is a Snapshot object.\n });\n\n //-\n // From {@link PubSub#snapshot}:\n //-\n const snapshot = pubsub.snapshot('my-snapshot');\n // snapshot is a Snapshot object.\n\n //-\n // Create a snapshot with {module:pubsub/subscription#createSnapshot}:\n //-\n const subscription = pubsub.subscription('my-subscription');\n\n subscription.createSnapshot('my-snapshot', (err, snapshot) =\u003e {\n if (!err) {\n // `snapshot` is a Snapshot object.\n }\n });\n\n //-\n // Seek to your snapshot:\n //-\n const subscription = pubsub.subscription('my-subscription');\n\n subscription.seek('my-snapshot', (err) =\u003e {\n if (err) {\n // Error handling omitted.\n }\n });\n\nConstructors\n------------\n\n### (constructor)(parent, name)\n\n constructor(parent: Subscription | PubSub, name: string);\n\nConstructs a new instance of the `Snapshot` class\n\nProperties\n----------\n\n### metadata\n\n metadata?: google.pubsub.v1.ISnapshot;\n\n### name\n\n name: string;\n\n### parent\n\n parent: Subscription | PubSub;\n\nMethods\n-------\n\n### create(gaxOpts)\n\n create(gaxOpts?: CallOptions): Promise\u003cCreateSnapshotResponse\u003e;\n\nCreate a snapshot with the given name.\n\n\\*\\*This is only available if you accessed this object through .\\*\\*\n\nSnapshot#create\n\n**Example** \n\n\n const subscription = pubsub.subscription('my-subscription');\n const snapshot = subscription.snapshot('my-snapshot');\n\n const callback = (err, snapshot, apiResponse) =\u003e {\n if (!err) {\n // The snapshot was created successfully.\n }\n };\n\n snapshot.create('my-snapshot', callback);\n\n //-\n // If the callback is omitted, we'll return a Promise.\n //-\n snapshot.create('my-snapshot').then((data) =\u003e {\n const snapshot = data[0];\n const apiResponse = data[1];\n });\n\n### create(callback)\n\n create(callback: CreateSnapshotCallback): void;\n\n### create(gaxOpts, callback)\n\n create(gaxOpts: CallOptions, callback: CreateSnapshotCallback): void;\n\n### delete()\n\n delete(): Promise\u003cEmptyResponse\u003e;\n\nDelete the snapshot.\n\n**Example** \n\n\n snapshot.delete((err, apiResponse) =\u003e {});\n\n //-\n // If the callback is omitted, we'll return a Promise.\n //-\n snapshot.delete().then((data) =\u003e {\n const apiResponse = data[0];\n });\n\n### delete(callback)\n\n delete(callback: EmptyCallback): void;\n\n### formatName_(projectId, name)\n\n static formatName_(projectId: string, name: string): string;\n\n### seek(gaxOpts)\n\n seek(gaxOpts?: CallOptions): Promise\u003cSeekResponse\u003e;\n\nSeeks an existing subscription to the snapshot.\n\n\\*\\*This is only available if you accessed this object through .\\*\\*\n\nSnapshot#seek\n\n**Example** \n\n\n const subscription = pubsub.subscription('my-subscription');\n const snapshot = subscription.snapshot('my-snapshot');\n\n snapshot.seek((err, apiResponse) =\u003e {});\n\n //-\n // If the callback is omitted, we'll return a Promise.\n //-\n snapshot.seek().then((data) =\u003e {\n const apiResponse = data[0];\n });\n\n### seek(callback)\n\n seek(callback: SeekCallback): void;\n\n### seek(gaxOpts, callback)\n\n seek(gaxOpts: CallOptions, callback: SeekCallback): void;"]]