Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | // Initialize Ottoman connection
const {
Ottoman, getModel, Schema, SearchConsistency,
} = require('ottoman');
const ottoman = new Ottoman();
ottoman.connect({
connectionString: 'couchbase://localhost',
bucketName: 'messageBucket',
username: 'user',
password: 'password',
});
const modelOptions = {
scopeName: 'messageScope',
collectionName: 'messageCollection',
};
const schema = new Schema({
text: { type: String },
});
ottoman.model('message', schema, modelOptions);
ottoman.start();
// Setup feathers service
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const { Service } = require('feathers-ottoman');
// Creates an ExpressJS compatible Feathers application
const app = express(feathers());
// Parse HTTP JSON bodies
app.use(express.json());
// Parse URL-encoded params
app.use(express.urlencoded({ extended: true }));
// Host static files from the current folder
app.use(express.static(__dirname));
// Add REST API support
app.configure(express.rest());
// Register a Couchbase message service
app.use('/messages', new Service({
Model: getModel('message'),
ottoman: {
lean: true,
consistency: SearchConsistency.LOCAL,
},
paginate: {
default: 10,
max: 100,
},
}));
// Register a nicer error handler than the default Express one
app.use(express.errorHandler());
// Create a dummy Message
app.service('messages').create({
text: 'Message created on Couchbase server',
}).then((message) => {
console.log('Created messages', message);
});
app.listen(3030).on('listening', () => console.log('feathers-ottoman example started'));
|