@google-cloud/connect-datastore

中文文档
7.0.1发布于 2024/06/26Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 5371

Google Cloud Datastore session store for Express/Connect

此软件包已被标记为弃用

package no longer maintained

原始使用文档
文档目录6 节
  1. Installation
  2. Configuration
  3. Usage Example
  4. Expiration
  5. Contributing
  6. License
Google Inc. logo

THIS REPOSITORY AND PACKAGE WILL BE DEPRECATED IN JULY 2024

Google Cloud Datastore Sessions

NPM

@google-cloud/connect-datastore is a Google Cloud Datastore session store backed by @google-cloud/datastore.

Note: Cloud Datastore is a persistent, distributed, transactional database. Often, it's more appropriate to choose a different storage solution for sessions such as Memcache or Redis as their designs offer much faster operation in this use case.

Installation

npm install @google-cloud/connect-datastore

Configuration

You must have a Google Cloud project and credentials.

See gcloud node's documentation on setting up authentication.

Usage Example

const {Datastore} = require('@google-cloud/datastore');
const {DatastoreStore} = require('@google-cloud/connect-datastore');
const express = require('express');
const session = require('express-session');

const app = express();

app.use(session({
  store: new DatastoreStore({
    kind: 'express-sessions',

    // Optional: expire the session after this many milliseconds.
    // note: datastore does not automatically delete all expired sessions
    // you may want to run separate cleanup requests to remove expired sessions
    // 0 means do not expire
    expirationMs: 0,

    dataset: new Datastore({

      // For convenience, @google-cloud/datastore automatically looks for the
      // GCLOUD_PROJECT environment variable. Or you can explicitly pass in a
      // project ID here:
      projectId: process.env.GCLOUD_PROJECT,

      // For convenience, @google-cloud/datastore automatically looks for the
      // GOOGLE_APPLICATION_CREDENTIALS environment variable. Or you can
      // explicitly pass in that path to your key file here:
      keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS
    })
  }),
  secret: 'my-secret'
}));

Expiration

If a session is fetched with the delta between the createdAt time and current time greater than expirationMs, the session will not be returned and will instead be destroyed.

Datastore does not support a ttl, and tokens are only deleted if a session is fetched. You will likely want to implement logic to occasionally delete expired sessions.

Contributing

License

版本与发布记录

@google-cloud/connect-datastore 共发布 16 个版本,首次发布于 2017/01/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
7.0.1latest2024/06/262 年前
7.0.02023/08/113 年前
6.0.12022/09/264 年前
6.0.02022/06/214 年前
5.0.3legacy-102021/08/265 年前
5.0.22020/12/035 年前

其他发布通道:legacy-8 → 4.0.0,legacy-10 → 5.0.3。

关于 @google-cloud/connect-datastore 的常见问题

@google-cloud/connect-datastore 是什么?

Google Cloud Datastore session store for Express/Connect注意:该包已被作者标记为弃用——package no longer maintained

如何安装 @google-cloud/connect-datastore?

在项目目录运行 npm install @google-cloud/connect-datastore,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:express-session(^1.17.1)、@google-cloud/datastore(^9.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@google-cloud/connect-datastore 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@google-cloud/connect-datastore 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@google-cloud/connect-datastore 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@google-cloud/connect-datastore 可以商用吗?

@google-cloud/connect-datastore 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@google-cloud/connect-datastore 的下载量有多少?

根据 npm 官方下载统计,@google-cloud/connect-datastore 在 2026/10/17 – 2026/11/15 这 30 天内被下载 5,371 次,日均约 179 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@google-cloud/connect-datastore 还在维护吗?

最新版本 7.0.1 发布于 2024/06/26(2 年前);至今共发布 16 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/01/10。作者已将其标记为弃用,新项目建议寻找替代方案。