npm install feathers-mongoose-service --save
Important: Read over the Feathers documentation, specifically the section on Services. All of the Feathers REST and Socket API requests are supported.
Run the following:
node example/index.js
Open your browser to http://localhost:8080/user.
There will likely be an empty array in response. This is because you have no User
s, yet.
I recommend the Postman extension for Chrome if you would like an easy to use REST Client.
var customService = new mongooseService(modelName, mongooseSchema, mongooseConnection);
See Mongoose Schema Guide for more information on defining your schema.
Skip to Step 3 for the important part.
// Get Feathers
var feathers = require('feathers');
// Get Mongoose
var mongoose = require('mongoose');
// Get Mongoose-Service
var mongooseService = require('feathers-mongoose-service');
// Get Mongoose
var mongoose = require('mongoose');
// Create your connection to Mongo
var connection = mongoose.connect('mongodb://localhost/test');
// Create your Mongoose-Service, for a `User`
var userService = mongooseService('user', {
email: {type : String, required : true, index: {unique: true, dropDups: true}},
firstName: {type : String, required : true},
lastName: {type : String, required : true},
age: {type : Number, required : true},
password: {type : String, required : true, select: false},
skills: {type : Array, required : true}
}, connection);
// Setup Feathers
var app = feathers();
// Configure Feathers
app.use(feathers.logger('dev')); // For debugging purposes.
// ................
var port = 8080;
// ................
app.configure(feathers.socketio())
.use('/user', userService) // <-- Register your custom Mongoose-Service with Feathers
.listen(port, function() {
console.log('Express server listening on port ' + port);
});
// Get Feathers
var feathers = require('feathers');
// Get Mongoose
var mongoose = require('mongoose');
// Get Mongoose-Service
var mongooseService = require('feathers-mongoose-service');
// Create your connection to Mongo
var connection = mongoose.connect('mongodb://localhost/test');
// Create your Mongoose-Service, for a `User`
var userService = mongooseService('user', {
email: {type : String, required : true, index: {unique: true, dropDups: true}},
firstName: {type : String, required : true},
lastName: {type : String, required : true},
age: {type : Number, required : true},
password: {type : String, required : true, select: false},
skills: {type : Array, required : true}
}, connection);
// Setup Feathers
var app = feathers();
// Configure Feathers
app.use(feathers.logger('dev')); // For debugging purposes.
// ................
var port = 8080;
// ................
app.configure(feathers.socketio())
.use('/user', userService) // <-- Register your custom Mongoose-Service with Feathers
.listen(port, function() {
console.log('Express server listening on port ' + port);
});
MIT