Questions tagged [hapi.js]

Hapi is a rich Node.js framework for building web applications and services. It is a simple to use configuration-centric framework with built-in support for input validation, caching, authentication, and other essential facilities.

Hapi is a rich Node.js framework for building web applications and services. It is a simple to use configuration-centric framework with built-in support for input validation, caching, authentication, and other essential facilities.


##Community


##Other useful links

1358 questions
139
votes
8 answers

How to destroy JWT Tokens on logout?

I am using jwt plugin and strategy in hapijs. I am able to create jwt token while login user and authenticate other API using the same token through 'jwt' strategy. I am setting the token in request.state.USER_SESSION as a cookie where USER_SESSION…
Garima
  • 1,566
  • 2
  • 11
  • 14
138
votes
6 answers

How do Express and hapi compare to each other?

From web application design and development point of view, how do Express and Hapi compare to each other? For basic examples they seem similar, however I'm interested to learn more about key differences in overall application structure. For example,…
Ali Shakiba
  • 20,549
  • 18
  • 61
  • 88
106
votes
7 answers

Joi validation of array

trying to validate that an array has zero or more strings in one case and that it has zero or more objects in another , struggling with Joi docs :( validate: { headers: Joi.object({ 'content-type': "application/vnd.api+json", …
1977
  • 2,580
  • 6
  • 26
  • 37
60
votes
7 answers

How to store routes in separate files when using Hapi?

All of the Hapi examples (and similar in Express) shows routes are defined in the starting file: var Hapi = require('hapi'); var server = new Hapi.Server(); server.connection({ port: 8000 }); server.route({ method: 'GET', path: '/', handler:…
Centurion
  • 14,106
  • 31
  • 105
  • 197
58
votes
2 answers

How to allow any other key in Joi

I have a simple requirement. I tried to search on the internet as well as documentation but failed. So here is what I want to achieve: I have a schema: const schema = Joi.object().keys({ a: Joi.string().required(), b:…
Anand Undavia
  • 3,493
  • 5
  • 19
  • 33
48
votes
4 answers

Joi validation return only one error message

I have a three field form made of a name field, email field and a textarea. I'm using Joi 4.7.0 version along with hapijs. I use the object below validate the input. I receive the data object from an ajax call. When I fill all the three fields with…
Mazzy
  • 13,354
  • 43
  • 126
  • 207
39
votes
2 answers

Multipart HTTP response

The goal is for a Node.js / hapi API server to respond to a browser's AJAX request with two things: A media file (e.g. an image) A JSON object with metadata about the file These are two separate items only because binary data cannot easily be…
Seth Holladay
  • 8,951
  • 3
  • 34
  • 43
37
votes
2 answers

Joi validation multiple conditions

I have the following schema: var testSchema = Joi.object().keys({ a: Joi.string(), b: Joi.string(), c: Joi.string().when('a', {'is': 'avalue', then: Joi.string().required()}) }); but I would like to add a condition on c field…
user2468170
  • 1,234
  • 2
  • 15
  • 19
32
votes
1 answer

Joi object validation: How to validate values with unknown key names?

I have an object with key names I cannot possibly know - they are created by user. However I do know what values they (keys) are going to store, and they (values) are going to be ISO strings. How do I validate those values? And, optionally, how do I…
wscourge
  • 10,657
  • 14
  • 59
  • 80
30
votes
7 answers

Joi validator conditional schema

I need to create dynamic schema to validate my api request query in node js using Joi validator depending on a key in the request query. Say the following below mentioned pattern are my valid queries. I'm using hapi/joi version 16.1.8 Combination…
Nitheesh
  • 19,238
  • 3
  • 22
  • 49
30
votes
6 answers

Using Joi, require one of two fields to be non empty

If I have two fields, I'd just like to validate when at least one field is a non empty string, but fail when both fields are empty strings. Something like this does not validate var schema = Joi.object().keys({ a: Joi.string(), b:…
Brendan
  • 809
  • 1
  • 8
  • 13
23
votes
5 answers

JOI email validation

Im using Joi library as standalone validator for my CRA project but when firing email() validator im getting cryptic error Uncaught Error: Built-in TLD list disabled
Konrad Albrecht
  • 1,701
  • 1
  • 9
  • 20
23
votes
3 answers

JOI :allow null values in array

I am trying to add a validation for array in a POST request Joi.array().items(Joi.string()).single().optional() I need to allow null values in the payload. Can you please tell me how this can be done ?
user1110790
  • 787
  • 2
  • 8
  • 27
23
votes
3 answers

hapijs joi validation , just validate one field and to allow any field

I want to validate one field and to allow another fields without validation; by example just to validate: "firstname" field. In my code when I comment 'payload', hapi allow me to record any field, when I uncomment 'payload' hapijs dont allow me…
stackdave
  • 6,655
  • 9
  • 37
  • 56
23
votes
3 answers

How to log all requests made to a hapi server without using a logging library?

I'd like to see a nice log with short info about each request to my server, for use during development. I've seen the documentation on http://hapijs.com/api#request-logs, but I couldn't understand enough of it to get it working. What should I pass…
mik01aj
  • 11,928
  • 15
  • 76
  • 119
1
2 3
90 91