1

I would like to create a way to read multiple files, each of which contain the definition of one Joi schema, and then load/push them into an object or array that I can call from my Node app.

Normally, this is done inline in code:

var schema = Joi.object().keys({
    a: Joi.string()
});

How should I define each Joi schema in one file, and how do I load them such that they are instantiated and usable in the main app?

4

1 回答 1

4

像这样将每个模式放在自己的文件中

// save this as carSchema.js
var Joi = require('joi')

module.exports = Joi.object().keys({
  a: Joi.string()
})

require像这样加载它们

// app.js
var schemas = [
  require('./carSchema'),
  require('./bikeSchema'),
  require('./shoeSchema')]
于 2015-12-31T19:06:37.950 回答