Last active
February 12, 2016 20:25
-
-
Save wuyuanyi135/2a52b29f294bcded9991 to your computer and use it in GitHub Desktop.
TypeError: Cannot read property 'service' of undefined
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var feathers = require('feathers'); | |
var hooks = require('feathers-hooks'); | |
var rest = require('feathers-rest'); | |
var socketio = require('feathers-socketio'); | |
var bodyParser = require ('body-parser'); | |
var authentication = require ('feathers-authentication').default; | |
var authHooks = require('feathers-authentication').hooks; | |
var mongoose = require('mongoose'); | |
var service = require ('feathers-mongoose'); | |
mongoose.Promise = global.Promise; | |
mongoose.connect('mongodb://localhost:27017/riddle'); | |
var app = feathers() | |
.configure(rest()) | |
.configure(socketio()) | |
.configure(hooks()) | |
.use(bodyParser.json()) | |
.use(bodyParser.urlencoded({ extended: true })) | |
.configure(authentication({ | |
token:{ | |
secret: 'InYATTDuYA' | |
}, | |
local: { | |
usernameField:"username" | |
} | |
})); | |
// Define Schema | |
var Schema = mongoose.Schema; | |
var userSchema = new Schema({ | |
username: { | |
type: String, | |
required: true, | |
index: {unique: true, dropDups: true} | |
}, | |
password: {type: String, required: true}, | |
createdAt: {type: Date, 'default': Date.now}, | |
}); | |
var userModel = mongoose.model('user', userSchema); | |
// route user | |
app.use('/', service({Model: userModel})); | |
// hash password hook | |
var userService = app.service('/'); | |
userService.before( | |
{ | |
create: [authHooks.hashPassword('password')] | |
} | |
) | |
// jsonify error | |
app.use(function(error, req, res, next){ | |
debugger; | |
console.log(error) | |
res.status(error.code); | |
res.json(error); | |
}) | |
app.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "some-problem", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"body-parser": "^1.9.0", | |
"feathers": "2.0.0-pre.4", | |
"feathers-hooks": "^1.0.0-pre.4", | |
"feathers-mongoose": "^3.3.0", | |
"feathers-primus": "^1.3.2", | |
"feathers-rest": "^1.2.2", | |
"feathers-socketio": "^1.3.2", | |
"mongoose": "^4.4.3", | |
"socket.io-client": "^1.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One thing, your
devDependencies
should bedependencies