-
Notifications
You must be signed in to change notification settings - Fork 1
1. Connect
Stuyk edited this page Jul 2, 2023
·
3 revisions
Create a TypeScript resource, and create a connection inside of it.
Here's an example TypeScript Resource that shows exactly how to do that.
import * as alt from 'alt-server';
import * as crc from '@stuyk/cross-resource-cache';
crc.database.connect('mongodb://127.0.0.1:27017', 'mydatabase');
crc.database.onReady(() => {
alt.log('Initialized database access for all resources!');
});
If you want to use the connection in other resources, you must use crc.database.onReady
.
It's a function that initializes
the connect in the resource after initial credentials are provided in another resource.
import * as alt from 'alt-server';
import * as crc from '@stuyk/cross-resource-cache';
crc.database.onReady(() => {
alt.log('I have database access in resource 2 now!');
});