Node.js SDK
Official Node.js SDK for the JSON2Video REST API.
- Repository: github.com/JSON2Video/json2video-nodejs-sdk
- npm package:
@json2video/json2video-sdk
Install
npm install @json2video/json2video-sdk
Minimal example
const { Movie } = require('@json2video/json2video-sdk');
const movie = new Movie();
movie.setAPIKey(process.env.J2V_API_KEY);
movie.setResolution('full-hd');
const scene = movie.addScene();
scene.addElement({
type: 'text',
text: 'Hello, JSON2Video',
duration: 5,
style: '001',
});
const result = await movie.render(); // POST /v2/movies.
const status = await movie.waitToFinish(); // Polls GET /v2/movies.
console.log(status.movie.url);
Configuration
| Method | Purpose |
|---|---|
setAPIKey(key) |
Sets the x-api-key header. |
setResolution(preset) |
Convenience wrapper for movie.resolution. |
setQuality(q) |
Convenience wrapper for movie.quality. |
addScene() |
Appends a scene; returns a Scene builder. |
addElement(obj) |
Adds a top-level (movie-wide) element. |
render() |
Submits the movie and returns the API response. |
waitToFinish() |
Polls GET /v2/movies until the status is terminal. |
The SDK builds the JSON payload documented in Movie JSON. Anything that can be expressed in the REST payload can be expressed via addElement() and friends — pass through any property by name.
Error handling
API failures reject with Error objects carrying the HTTP status and message. See Errors for the full list.
TypeScript
The SDK ships type definitions. Import types alongside the runtime symbols:
import { Movie, MovieResponse } from '@json2video/json2video-sdk';