Use the official Mux SDK for Node.js to call the Mux API from your server. The SDK handles authentication and wraps each API endpoint in native JavaScript code.
The Mux SDK for Node.js wraps the Mux REST API in native JavaScript code. Use this SDK when your server application runs on Node.js. You can create assets, manage live streams, and query Mux Data without manual HTTP requests.
Add a dependency on the @mux/mux-node package via npm or yarn.
npm install @mux/mux-nodeTo start, you'll need a Mux access token. Once you've got that, you're off to the races!
import Mux from '@mux/mux-node';
const mux = new Mux({
tokenId: process.env.MUX_TOKEN_ID,
tokenSecret: process.env.MUX_TOKEN_SECRET
});
const asset = await mux.video.assets.create({
input: [{ url: 'https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4' }],
playback_policy: ['public'],
});Check out the Mux Node SDK docs for more information.