An example for learning Node.js - a REST user module.
- general response:
- status: 400, body: { message: validation error detail }
- status: 500, body: { message: 'db error' }
- request
- body: { username, password }
- response:
- status: 200, body: { username, createdAt }
- status: 400, body: { message: 'already exists' }
- request
- param: username
- response:
- status: 200, body: { username, createdAt }
- status: 404, body: { message: 'not found' }
- request
- param: username
- body: { oldPassword, newPassword }
- response:
- status: 200, body: { username, updatedAt }
- status: 404, body: { message: 'not found' }
- request
- param: username
- body: { password }
- response:
- status: 200, body: { message: 'ok' }
- status: 404, body: { message: 'not found' }
- request
- param: username
- body: { password }
- response:
- status: 200, body: { username, sessionId, sessionCreatedAt }
- status: 404, body: { message: 'not found' }
- request
- param: username, sessionId
- response:
- status: 200, body: { message: 'ok' }
- status: 404, body: { message: 'not found' }
use hellouserjs;
db.createUser({
user: "hellouserjsu",
pwd: "hellouserjsp",
roles: [{role: "readWrite", db: "hellouserjs"}]
});
Assuming that mongodb is installed via brew
. The config file is located
at /usr/local/etc/mongod.conf
. Append to the config file with:
security.authorization: enabled
mongod --config /usr/local/etc/mongod.conf