Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
express-reuse
Advanced tools
Readme
A lightweight framework that makes reusing pieces of your express app easy. More detailed documentation available here
The simplest way to use express-reuse
is to install a strategy. For now, let's use express-reuse-local-login
.
$ npm install express-reuse
$ npm install express-reuse-local-login
Steps:
express-reuse
requires you to use at least body-parser
, cookie-parser
, and some sort of session handling middleware. In this case we're using express-session
.
app.use(cookieParser())
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
app.use(expressSession({
secret : /* Your session secret */ ,
//these can be true or false
resave: true,
saveUninitialized: true,
cookie: {
secure: true
}
}))
This step is optional. If you don't want to use transactional emails, simply include noEmail: true
in the options object when we set up express-reuse
.
For a more detailed explanation on what can be done here, see the documentation for email-templates
. The emailOptions object we create in this section gets passed directly to email-templates
.
First we need a nodemailer
transport. This example uses ethereal.email.
var transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
auth: {
user: /* your email */,
pass: /* your password */
}
})
Next we need to setup a folder with our email templates. The templates we need will depend on the strategy being used. In this case, express-reuse-local-login
requires four templates.
emails
- emailConfirm
- emailConfirmThankYou
- forgotPassword
- passwordChanged
See the email-templates
documentation for a more detailed explanation about how to set these up.
Finally, we create our emailOptions object.
var emailOptions = {
views: {
root: /* directory containing email templates */
},
message: {
from: "noreply@yourapp.com"
},
transport: transporter
}
Out of the box, express-reuse
works with mongoose
. But it can be easily configured to work with any database you want. If you want to work with another database module, see the documentation here.
First, connect to the database.
mongoose.connect( /* Your database URL */)
.then(() => {
console.log("Database is connected")
})
.catch((err) => {
console.log("Can not connect to the database" + err)
})
Then create a mongoose
User model. The fields that need to be in the model will depend on the particular strategy being used. For express-reuse-local-login
your schema will look like this.
var userSchema = new mongoose.Schema({
email: {type: String, select: false},
password: {type: String, select: false},
//optional if not using transactional emails
confirmEmailToken: {type: String, select: false},
resetPasswordToken: {type: String, select: false},
resetPasswordExpires: {type: Date, select: false},
emailConfirmed: {type: Boolean, select: false, default: false},
/* Other fields related specifically to your app */
})
var User = mongoose.model("User", userSchema)
It is not required that the fields be set to select:false
. This just shows that the strategy will work correctly even if you do.
Now we're ready to setup express-reuse
. First require the packages:
var expressReuse = require('express-reuse')
var expressReuseLocalLogin = require('express-reuse-local-login')
Then we tell express-reuse
to use the local login strategy.
expressReuse.useStrategy(expressReuseLocalLogin)
Now we app.use()
and provide our options object to express-reuse
. The options object contains the User model and emailOptions we set up earlier.
app.use("/auth", expressReuse({
userModel: User,
//For transactional emails
emailOptions: emailOptions
//For no emails
noEmail: true
})
express-reuse
is fully configurable and customizable. For more information, see the documentation.
FAQs
Lightweight express app framework that makes using and creating reusable routes easy.
The npm package express-reuse receives a total of 5 weekly downloads. As such, express-reuse popularity was classified as not popular.
We found that express-reuse demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.