unsplash-js is the official JavaScript wrapper for the Unsplash API, providing a convenient way to interact with Unsplash's photo services. The library abstracts away direct HTTP requests, offering methods for accessing photos, users, collections, and search functionalities. The current stable version is 7.0.20. Historically, it saw frequent minor updates for new API features and bug fixes, as evidenced by the recent v7.0.x releases. However, as of the latest README, the project has been officially archived and no longer receives support or updates, meaning new API features from Unsplash will not be integrated into this library, and critical bug fixes are unlikely. Developers are now directed to use the Unsplash developer documentation to make requests directly to the API, rather than relying on this wrapper.
npm install unsplash-jsVerified import paths — ran on the pinned version, not inferred.
Initializes the Unsplash API client with an access key and fetches a random landscape photo, demonstrating basic API interaction and best practices for Node.js with `node-fetch` and TypeScript.
Migrate your application to make direct HTTP requests to the Unsplash API using `fetch` or a similar HTTP client, following the official Unsplash API documentation for endpoints, authentication, and guidelines.
For Node.js, install `node-fetch` (`npm i node-fetch`) and then either set `global.fetch = require('node-fetch');` or pass it directly: `createApi({ accessKey: 'YOUR_KEY', fetch: require('node-fetch') });`Use a type assertion: `fetch: nodeFetch.default as unknown as typeof fetch,` when passing `node-fetch.default` to `createApi`. Alternatively, stick to `node-fetch` v2 if possible.
Always embed images using the URLs provided by the API (hotlinking). Display the photographer's name (e.g., 'Photo by [Photographer Name] / Unsplash'). When users download a photo from your application, trigger the Unsplash download endpoint (`photo.links.download_location`).
Install `node-fetch` (`npm install node-fetch`) and set it globally (`global.fetch = require('node-fetch');`) or pass it directly to `createApi`: `createApi({ accessKey: 'YOUR_KEY', fetch: require('node-fetch') });`Use a type assertion when passing `node-fetch.default`: `fetch: nodeFetch.default as unknown as typeof fetch,`.
Double-check your Unsplash developer account for the correct 'Access Key' and ensure it's properly configured in your application. Register as a developer if you haven't already.