# スクリプト

ニフクラ mobile backend（以下、NCMB）で使っているプログラム（スクリプト）を、FirebaseのCloud Functions（以下、Firebase Functions）に変更する手順について説明します。

NCMBで提供されている[サンプルスクリプト](https://mbaas.nifcloud.com/doc/current/script/sample_javascript.html)を例に、これをFirebase Functionsにどう移行するかを解説します。

利用可能なサンプルは3種類あります。Firebase Functions開発環境の作成とサンプルに共通する共通項目のドキュメントを確認後、各サンプルを詳細にご覧ください。

本ドキュメントで扱うコードはGitHubリポジトリにて公開しています。

#### サーバーサイドコード（Firebase Functions）

{% embed url="<https://github.com/monaca-samples/firebase-functions-server-sample>" %}

#### アプリ側コード (Monaca プロジェクト)

{% embed url="<https://github.com/monaca-samples/firebase-functions-app-sample>" %}

{% content-ref url="/pages/DAscngBXol4yuOdbIo3E" %}
[Firebase Functions開発環境の作成](/migration-guide/nifcloud/sukuriputo/firebase-functionsno.md)
{% endcontent-ref %}

{% content-ref url="/pages/qv9sqivzj9FaWCzMyB2b" %}
[サンプル共通項目](/migration-guide/nifcloud/sukuriputo/sanpuru.md)
{% endcontent-ref %}

{% content-ref url="/pages/nqJPJFGx2BhyETRZIW7j" %}
[サンプル1（GETサンプル）](/migration-guide/nifcloud/sukuriputo/sanpuru1getsanpuru.md)
{% endcontent-ref %}

{% content-ref url="/pages/lqH9J9Os9VIeJghWMmdf" %}
[サンプル2（POSTサンプル）](/migration-guide/nifcloud/sukuriputo/sanpuru2postsanpuru.md)
{% endcontent-ref %}

{% content-ref url="/pages/PrbPY7btAJC1qH4syepR" %}
[サンプル3（DELETEサンプル）](/migration-guide/nifcloud/sukuriputo/sanpuru3deletesanpuru.md)
{% endcontent-ref %}

{% content-ref url="/pages/ZwRv1KvYnRgVHZZROMap" %}
[エミュレータでのテスト](/migration-guide/nifcloud/sukuriputo/emyurtadenotesuto.md)
{% endcontent-ref %}

***

## Firebase Functionsの特徴

1. **ローカル開発環境のエミュレータ使用**: Firebaseでは、開発者が自分のコンピュータ上でエミュレータを使用して、Firebase Functionsの動作をテストできます。これにより、安全に動作検証を行うことが可能になります。
2. **本番環境での課金リスクの回避**: 無限ループのようなバグは、本番環境で実行されると高額な課金が発生する可能性があります。そのため、エミュレータを使った検証は非常に重要です。
3. **課金に関する情報**: Firebaseの課金については、Firebaseの公式ウェブサイトにある価格設定ページで詳細を確認できます。
4. **アクセス制限の設定**: Firebaseでは、Rulesを使用してアクセス制限を設定できます。ただし、このドキュメントではRulesの詳細には触れていません。

## NCMBスクリプトとFirebase Functionsの違い

NCMBスクリプトとFirebase Functionsは、ウェブアプリやモバイルアプリ開発で使われるバックエンドの機能を提供するツールですが、いくつかの違いがあります。

1. **プログラミング言語のサポート**：
   * **NCMBスクリプト**：JavaScriptやRubyでの記述が可能です。
   * **Firebase Functions**：JavaScript、TypeScript、Pythonがサポートされています。
2. **データオブジェクトの取り扱い**：
   * **NCMBスクリプト**：JavaScriptのオブジェクト（NCMBObject）としてデータを扱います。このオブジェクトには、それぞれのオブジェクトを識別するためのユニークなID（オブジェクトID）が含まれています。
   * **Firebase Functions**：データはドキュメントとして扱われますが、そのJSON表現にはIDが含まれていません。そのため、IDをデータに埋め込む必要がある場合、別途実装する必要があります。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ja.docs.monaca.io/migration-guide/nifcloud/sukuriputo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
