title: JavaScript/TypeScript Setup sidebar_position: 6 id: javascript license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Fory JavaScript/TypeScript provides xlang Object Serialization, generated models, Node.js gRPC, and browser gRPC-Web clients. Packages are published on npm. The core package works without native acceleration; the optional @apache-fory/hps Node.js fast path requires Node.js 20 or later.
node --version npm --version
Install the core package:
npm install @apache-fory/core@1.5.0
Define a schema and run an xlang round trip:
const { default: Fory, Type } = require("@apache-fory/core"); const userType = Type.struct( { typeName: "example.User" }, { id: Type.int64(), name: Type.string(), }, ); const fory = new Fory(); const { serialize, deserialize } = fory.register(userType); const bytes = serialize({ id: 1n, name: "Alice" }); console.log(deserialize(bytes));
node example.cjs
JavaScript uses xlang mode. Continue with JavaScript/TypeScript Object Serialization, xlang types, configuration, and schema evolution.
For the optional Node.js string fast path, install the matching package version:
npm install @apache-fory/core@1.5.0 @apache-fory/hps@1.5.0