What is @supabase/supabase-js?
@supabase/supabase-js is a JavaScript client library for interacting with Supabase, an open-source Firebase alternative. It allows developers to perform a variety of database operations, authentication, and real-time subscriptions with ease.
What are @supabase/supabase-js's main functionalities?
Database Operations
This feature allows you to perform CRUD operations on your database. The code sample demonstrates how to fetch data from a table using the Supabase client.
const { createClient } = require('@supabase/supabase-js');
const supabase = createClient('https://your-project.supabase.co', 'public-anon-key');
async function fetchData() {
let { data, error } = await supabase
.from('your_table')
.select('*');
if (error) console.error(error);
else console.log(data);
}
fetchData();
Authentication
This feature allows you to manage user authentication, including sign-up, sign-in, and sign-out. The code sample demonstrates how to sign up a new user.
const { createClient } = require('@supabase/supabase-js');
const supabase = createClient('https://your-project.supabase.co', 'public-anon-key');
async function signUp() {
let { user, error } = await supabase.auth.signUp({
email: 'example@example.com',
password: 'example-password'
});
if (error) console.error(error);
else console.log(user);
}
signUp();
Real-time Subscriptions
This feature allows you to subscribe to real-time changes in your database. The code sample demonstrates how to listen for new rows being inserted into a table.
const { createClient } = require('@supabase/supabase-js');
const supabase = createClient('https://your-project.supabase.co', 'public-anon-key');
supabase
.from('your_table')
.on('INSERT', payload => {
console.log('New row added!', payload);
})
.subscribe();
Other packages similar to @supabase/supabase-js
firebase
Firebase is a comprehensive app development platform by Google that offers a variety of tools including Firestore for database operations, Firebase Auth for authentication, and Firebase Realtime Database for real-time data synchronization. Compared to @supabase/supabase-js, Firebase offers a more extensive suite of services but is not open-source.
hasura
Hasura is an open-source engine that provides instant GraphQL APIs on your data. It supports real-time subscriptions and integrates well with existing databases. Compared to @supabase/supabase-js, Hasura focuses on GraphQL APIs and offers more advanced querying capabilities.
parse
Parse is an open-source backend framework that provides a variety of features including a database, user authentication, and real-time notifications. It is similar to @supabase/supabase-js in its open-source nature and feature set but has a different architecture and community support.
Supabase JS
Commands
npm run clean
- Remove lib/
directorynpm test
- Run tests with linting and coverage results.npm run test:integration
- Run the integration tests without docker (requires you to run the docker container separately)npm run test:integration:full
- Run the integration tests (requires docker to be running)npm test:only
- Run tests without linting or coverage.npm test:watch
- You can even re-run tests on file changes!npm test:prod
- Run tests with minified code.npm run test:examples
- Test written examples on pure JS for better understanding module usage.npm run lint
- Run ESlint with airbnb-confignpm run cover
- Get coverage report for your code.npm run build
- Babel will transpile ES6 => ES5 and minify the code.npm run build:umd
- Babel will transpile ES6 => UMD, minify the code and webpack to supabase.jsnpm run prepublish
- Hook for npm. Do all the checks before publishing your module.
Publishing
Bump the semver.
npm publish --access=public
We are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves. Thanks to these sponsors who are making the OSS ecosystem better for everyone.