使用Express,Mongodb作为服务器数据库的Node.js中的用户管理 [英] Users management in node js with express, mongodb as server database

查看:73
本文介绍了使用Express,Mongodb作为服务器数据库的Node.js中的用户管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找向我的网站添加用户管理的方法.

Looking for the way to add user management to my site.

站点:使用Node.js& Express,使用Express创建初始项目时,app.js文件包含以下几行:

Site: Working with Node.js & Express, when creating the initial project with Express, the app.js file contains these lines:

app.use('/', routes);
app.use('/users', users);

此外,在routes文件夹下创建了文件users.js.我的问题是如何管理用户,强制登录以及为普通用户/管理员用户显示不同的视图.我希望找到一个简单的示例/教程.

In addition, a file users.js is created under routes folder. My question is how to manage users, force login, and show different views for regular user / admin user. I wish to find a simple example / tutorial.

存储:使用MongoDB&猫鼬,我注意到数据库具有内置的Users文件夹.我想在MongoDB上保存用户数据(用户+密码+首选项).这样做的方式是什么?

Storage: Working with MongoDB & mongoose, I noticed the database has Users folder built-in. I want to save users data (user + password + preference) on MongoDB. What is the way to do this?

推荐答案

我遵循了本教程. https://scotch.io/tutorials/easy-node-authentication-在本地设置

Passport js可以很好地完成这项工作,而无需库就可以完成这项工作,只需要重新发明轮子即可.

Passport js does the job very nicely, doing this without a library would just require you to reinvent the wheel.

这篇关于使用Express,Mongodb作为服务器数据库的Node.js中的用户管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆