// Import the global admin namespaceimport*asadminfrom'firebase-admin';constapp:admin.app.App=admin.initializeApp();consttoken:string=awaitadmin.auth().createCustomToken('alice');constuser:admin.auth.UserRecord=awaitadmin.auth().getUser('bob');
// Import only what you needimport{initializeApp,App}from'firebase-admin/app';import{getAuth,UserRecord}from'firebase-admin/auth';constapp:App=initializeApp();consttoken:string=awaitgetAuth().createCustomToken('alice');constuser:UserRecord=getAuth().getUser('bob');
Node.js
// Import only what you needconst{initializeApp}=require('firebase-admin/app');const{getAuth}=require('firebase-admin/auth');constapp=initializeApp();consttoken=awaitgetAuth().createCustomToken('alice');constuser=getAuth().getUser('bob');
// With {type: module} in the package.json...// Import only what you needimport{initializeApp}from'firebase-admin/app';import{getAuth}from'firebase-admin/auth';constapp=initializeApp();consttoken=awaitgetAuth().createCustomToken('alice');constuser=getAuth().getUser('bob');
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-01 (世界標準時間)。"],[],[],null,["\u003cbr /\u003e\n\nVersion 10 of the Admin Node.js SDK introduces two important changes:\n\n- Support for Node.js 10 is discontinued (this is a **breaking change**)\n- The SDK has adopted a modular API pattern\n\nThis guide provides instructions and information to help developers upgrade\nexisting Node.js apps from earlier versions of the Admin SDK to v10.\n\nUpdate Node.js to v12 or higher\n\nWith the Admin Node.js SDK v10 release, Firebase has discontinued support for\nNode.js 10. Developers must use Node.js 12 or higher when using the Admin SDK.\nIf you're using the Admin Node.js SDK together with Cloud Functions for Firebase,\nmake sure that you have\n[upgraded your Node.js version](/docs/functions/manage-functions#upgrade-node10)\nto 12 or higher.\n\nUse modules instead of namespaces\n\nSince its inception, the Admin Node.js SDK has offered a stable API structured\nas a nested namespace hierarchy. As a result, you might have become familiar\nwith writing code that looks like this: \n\n // Import the global admin namespace\n import * as admin from 'firebase-admin';\n\n const app: admin.app.App = admin.initializeApp();\n\n const token: string = await admin.auth().createCustomToken('alice');\n\n const user: admin.auth.UserRecord = await admin.auth().getUser('bob');\n\nStarting from v10, the Admin Node.js SDK offers multiple module entry points\nwith named exports. We recommend developers to use these new entry points to\naccess the various APIs of the SDK, as opposed to using the global `admin`\nnamespace.\n\nHere's what the above example would look like with the new module\nentry points: \n\nTypeScript \n\n // Import only what you need\n import { initializeApp, App } from 'firebase-admin/app';\n import { getAuth, UserRecord } from 'firebase-admin/auth';\n\n const app: App = initializeApp();\n\n const token: string = await getAuth().createCustomToken('alice');\n\n const user: UserRecord = getAuth().getUser('bob');\n\nNode.js \n\n // Import only what you need\n const { initializeApp } = require('firebase-admin/app');\n const { getAuth } = require('firebase-admin/auth');\n\n const app = initializeApp();\n\n const token = await getAuth().createCustomToken('alice');\n\n const user = getAuth().getUser('bob');\n\nUsing v10 modular entry points\n\nNote that, in the examples above, you are no longer importing a global `admin`\nnamespace. Instead, you explicitly import only the symbols you need from several\nmodule entry points. Also, TypeScript developers no longer have to use triple-\nnested type identifiers like `admin.auth.UserRecord` and\n`admin.database.Reference`. Since each type belongs to exactly one module, you\ncan just import them by their short names like `UserRecord` and `Reference`.\n\nHere are all the module entry points available in the SDK as of v10:\n\n- firebase-admin/app\n- firebase-admin/auth\n- firebase-admin/database\n- firebase-admin/firestore\n- firebase-admin/instance-id\n- firebase-admin/machine-learning\n- firebase-admin/messaging\n- firebase-admin/project-management\n- firebase-admin/remote-config\n- firebase-admin/security-rules\n- firebase-admin/storage\n\nThe following table shows the replacement import syntax for each of the legacy\nnamespace functions:\n\n| **v9** | **v10** |\n|-----------------------------|------------------------------------------------------------------------------------------------------|\n| `admin.initializeApp()` | `import { initializeApp } from 'firebase-admin/app'` `initializeApp();` |\n| `admin.app()` | `import { getApp } from 'firebase-admin/ap'` `getApp();` |\n| `admin.credential.cert()` | `import { cert } from 'firebase-admin/app'` `cert();` |\n| `admin.auth()` | `import { getAuth } from 'firebase-admin/auth'` `getAuth();` |\n| `admin.database()` | `import { getDatabase } from 'firebase-admin/database'` `getDatabase();` |\n| `admin.firestore()` | `import { getFirestore } from 'firebase-admin/firestore'` `getFirestore();` |\n| `admin.instanceId()` | `import { getInstanceId } from 'firebase-admin/instance-id'` `getInstanceId();` |\n| `admin.machineLearning()` | `import { getMachineLearning } from 'firebase-admin/machine-learning'` `getMachineLearning();` |\n| `admin.messaging()` | `import { getMessaging } from 'firebase-admin/messaging'` `getMessaging()` |\n| `admin.projectManagement()` | `import { getProjectManagement } from 'firebase-admin/project-management'` `getProjectManagement();` |\n| `admin.remoteConfig()` | `import { getRemoteConfig } from 'firebase-admin/remote-config'` `getRemoteConfig();` |\n| `admin.securityRules()` | `import { getSecurityRules } from 'firebase-admin/security-rules'` `getSecurityRules()` |\n| `admin.storage()` | `import { getStorage } from 'firebase-admin/storage'` `getStorage();` |\n\nUse exported functions instead of methods on App\n\nIn the legacy API, the `App` object exposed a number of methods like\n`app.auth()` and `app.database()`. We recommend developers to avoid using these\nmethods, and instead use the same module entry points described above to obtain\nservice instances scoped to a given `App` object, and perform other app-specific\ntasks.\n\n| **v9** | **v10** |\n|---------------------------|---------------------------------------------------------------------------------------------------------|\n| `app.auth()` | `import { getAuth } from 'firebase-admin/auth';` `getAuth(app);` |\n| `app.database()` | `import { getDatabase } from 'firebase-admin/database';` `getDatabase(app);` |\n| `app.database(url)` | `import { getDatabaseWithUrl } from 'firebase-admin/database';` `getDatabaseWithUrl(url, app);` |\n| `app.firestore()` | `import { getFirestore } from 'firebase-admin/firestore'` `getFirestore(app);` |\n| `app.instanceId()` | `import { getInstanceId } from 'firebase-admin/instance-id'` `getInstanceId(app);` |\n| `app.machineLearning()` | `import { getMachineLearning } from 'firebase-admin/machine-learning'` `getMachineLearning(app);` |\n| `app.messaging()` | `import { getMessaging } from 'firebase-admin/messaging'` `getMessaging(app);` |\n| `app.projectManagement()` | `import { getProjectManagement } from 'firebase-admin/project-management'` `getProjectManagement(app);` |\n| `app.remoteConfig()` | `import { getRemoteConfig } from 'firebase-admin/remote-config'` `getRemoteConfig(app);` |\n| `app.securityRules()` | `import { getSecurityRules } from 'firebase-admin/security-rules'` `getSecurityRules(app);` |\n| `app.storage()` | `import { getStorage } from 'firebase-admin/storage'` `getStorage(app);` |\n| `app.delete()` | `import { deleteApp } from 'firebase-admin/app';` `deleteApp(app);` |\n\nES modules support\n\nNode.js 12 and above come with experimental support for ES modules, enabling\neven non-TypeScript developers to use the `export` and `import` keywords in\ntheir code. Starting from the v10 release, the Admin Node.js SDK also provides\nES modules support, so that developers implementing ES modules on plain Node.js\ncan import the SDK using `import` syntax.\n\nTo use ES modules with the Admin SDK, first make sure you have enabled ESM\nsupport for your Node.js runtime. This is usually done by adding a `\"type\":\n\"module\"` field to your `package.json` file. Then you can write application code\nthat looks like this: \n\n // With {type: module} in the package.json...\n\n // Import only what you need\n import { initializeApp } from 'firebase-admin/app';\n import { getAuth } from 'firebase-admin/auth';\n\n const app = initializeApp();\n\n const token = await getAuth().createCustomToken('alice');\n\n const user = getAuth().getUser('bob');"]]