balderdashy / balderdashy/sails

error: Sending 500 ("Server Error") response: ReferenceError: user is not defined at Object.createUser

Open
#4,474 8 comments 0 reactions 0 assignees View on GitHub
question try this out please
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

hello
I have a problem with new version of sails to connect to Sails-mongo. can you help me please?

**Sails version**: 1.0.2
**Node version**: 8.10 .0
**NPM version**: 5.6.0
**DB adapter name**: serve
**DB adapter version**: N/A
**Operating system**: win 10

datastore.js:
module.exports.datastores = {
default: {
adapter: 'sails-mongo',
url: 'mongodb://127.0.0.1:27017/server'
}
}
----------------------
module.exports.models = {
migrate: 'alter',

attributes: {
createdAt: { type: 'number', autoCreatedAt: true, },
updatedAt: { type: 'number', autoUpdatedAt: true, },
id: { type: 'string', columnName: '_id', required: true },
},

dataEncryptionKeys: {
default: '3X6yTfIErxEHDahmUxEdiRFg8rR8eU0/H8Z2AiGnNmU='
},

cascadeOnDestroy: true
};
-----------------------------
user.js
module.exports = {
attributes: {
name: {
type: 'string'
}
}
-----------------------------
userController.js
module.exports = {
createUser: (req, res) => {
console.log('hello world');
user.create({name: 'sample'}).exec((err, userCreated) => {
res.ok('userCreated');
})
}
};
------------------------
module.exports.routes = {
'get /add': {
controller: 'UserController',
action: 'createUser'
},

when i LIFT it and do a request i got below error. and i have a user collection in my server db on mongo.

error: Sending 500 ("Server Error") response:
ReferenceError: user is not defined at Object.createUser [as user/createuser] (E:\angular2\server-sails\test\api\controllers\UserController.js:20:5)

Contributor guide

Open the contributing guide

Research direction

Start in userController.js at createUser and compare the reported ReferenceError with the User model and Sails 1.0.2 conventions. Reproduce the GET /add request against the shown Mongo datastore, then verify that the request creates a user and returns successfully without the 500 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, node.js
Domain
backend, database
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.