Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
help-me-respond
Advanced tools
This is a simple response helper which should make you life a bit easier. It supports localization and friendly messages for users.
Your project is a nodejs server based on Express or something similar. Help-me-respond uses the res object from Express, which represents the HTTP response that an Express app sends when it gets an HTTP request.
npm i help-me-respond --save
Create a config folder and put default.json in it. (more cool config setup at https://github.com/lorenwest/node-config).
You will need to add the following to your default.json file. File naming is up to you :) This is a basic setup for the i18n-nodejs - https://github.com/eslam-mahmoud/i18n-nodejs
{
"lang": "en",
"langFile": "../../locales/locales.json"
}
{
"NO_SHARING_WITH_YOURSELF": {
"en": "You cannot share the link with yourslef"
},
"NOT_OWNER": {
"en": "You are not the owner"
}
}
Some messages returned from the server are too technical for the user. So we would like to differentiate between those messages and user friendly messages. Simply add the following to your default.json configuration file. Now you can add message names in the friendlyMessages array.
{
"friendlyMessages": [
]
}
Once the message name is in the above array, the response will have a key friendlyMessage which makes it easy for front-end to differentiate between messages.
res - Express res object
msg - string message, Error object, any other object
headers - array with http headers. If none provided the only header set by the library will be Content-type: application/json
returns HTTP response with 400 error code If no message is specified will return message - BAD REQUEST
returns HTTP response with 404 error code If no message is specified will return message - NOT FOUND
returns HTTP response with 403 error code If no message is specified will return message - FORBIDDEN
returns HTTP response with 403 error code If no message is specified will return message - UNAUTHENTICATED
response - an Express response object returns HTTP response with 502 error code
This can be used when you are quering third party API. E.g. You will receive an error reponse for you request. You can call this function with the original response object. This way you will differentiate between you own server errors and third party API problems
returns HTTP response with 200 success code
returns HTTP response with 201 success code
general function to return any HTTP code you want
{
"friendlyMessage": "I am a friendly successfull message"
}
{
"message": "I am a very technical success message that users do not want to see"
}
{
"code": 400,
"error": {
"friendlyMessage": "I am a friendly error message"
}
}
{
"code": 400,
"error": {
"message": "I am a very technical error message that users do not want to see"
}
}
FAQs
Simple nodejs Express http response helper
The npm package help-me-respond receives a total of 0 weekly downloads. As such, help-me-respond popularity was classified as not popular.
We found that help-me-respond 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.