Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-msgs

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-msgs - npm Package Compare versions

Comparing version 0.0.3 to 1.0.0

3

index.js

@@ -10,2 +10,3 @@

exports.sendJSON = msg200.sendJSON;
exports.sendHTML = msg200.sendHTML;
exports.send200 = msg200.send200;

@@ -18,3 +19,3 @@

exports.send403 = msg400.send403;
exports.send404 = msg400.send404;

@@ -21,0 +22,0 @@ exports.send405 = msg400.send405;

{
"name": "http-msgs",
"version": "0.0.3",
"version": "1.0.0",
"description": "Node module to handle to HTTP status codes",

@@ -5,0 +5,0 @@ "main": "index.js",

# http-msgs
Node module to handle to HTTP status codes
![verson](https://img.shields.io/badge/version-0.0.3-green.svg)
![verson](https://img.shields.io/badge/version-1.0.0-green.svg)
![License](https://img.shields.io/badge/License-MIT-yellowgreen.svg)

@@ -17,2 +17,4 @@

data = retun data is in JSON format
httpMsgs.sendHTML(req, res, html, resEnd)
this sends the responce in html format
```

@@ -40,13 +42,17 @@ ```

```
httpMsgs.send405(req, res, resEnd)
httpMsgs.send405(req, res, html, resEnd)
Method not supporetd i.e request.methods supported
if html argument is "", then sends the responce in JSON
```
```
httpMsags.send404(req, res, resEnd)
httpMsags.send404(req, res, html, resEnd)
Requested page not availeble
if html argument is "", then sends the responce in JSON
```
```
httpMsgs.send413 (req, res, resEnd)
httpMsgs.send413 (req, res, html, resEnd)
Requesting for large data, not supported.
if html argument is "", then sends the responce in JSON
```

@@ -57,5 +63,6 @@

```
httpMsgs.send500(req, res, err, resEnd)
httpMsgs.send500(req, res, err, html, resEnd)
This sends error status with error messages
err = this contains error message
if html argument is "", then sends the responce in JSON
```

@@ -62,0 +69,0 @@

@@ -1,2 +0,3 @@

let contentType ={"Content-Type" : "application/json"}
let contentTypeJSON ={"Content-Type" : "application/json"}
var contentTypeHTML = {"Content-Type" : "text/html"};

@@ -11,3 +12,3 @@ /*

// on succes
res.writeHead(200, contentType);
res.writeHead(200, contentTypeJSON);
if(data){

@@ -24,5 +25,19 @@ res.write(JSON.stringify(data));

exports.sendHTML = function(req, res, html, resEnd=true){
// on succes
res.writeHead(200, contentTypeHTML);
if(html){
res.write(JSON.stringify(html));
}
if(resEnd){
res.end();
}
}
exports.send200 = function(req, res, resEnd=true){
// 200
res.writeHead(200, contentType);
res.writeHead(200, contentTypeJSON);
if(resEnd){

@@ -29,0 +44,0 @@ res.end();

@@ -1,2 +0,2 @@

let contentType ={"Content-Type" : "application/json"}
let contentTypeJSON ={"Content-Type" : "application/json"}
/*

@@ -3,0 +3,0 @@ ======================

let contentType ={"Content-Type" : "application/json"}
var contentTypeJSON ={"Content-Type" : "application/json"};
var contentTypeHTML = {"Content-Type" : "text/html"};
/*

@@ -9,7 +11,28 @@ ======================

*/
exports.send403 = function(req, res, html = "", resEnd=true){
// Requested page not availeble
if (html == ""){
res.write(JSON.stringify({"data" : "forbidden"}));
res.writeHead(403,"Forbidden", contentTypeJSON);
}else{
res.write(html);
res.writeHead(403,"Forbidden", contentTypeHTML);
}
if(resEnd){
res.end();
}
}
exports.send404 = function(req, res, resEnd=true){
exports.send404 = function(req, res, html = "", resEnd=true){
// Requested page not availeble
res.writeHead(404,"Resource not found", contentType);
res.write(JSON.stringify({"data" : "Resource not found"}));
if (html == ""){
res.writeHead(404,"Resource not found", contentTypeJSON);
res.write(JSON.stringify({"data" : "Resource not found"}));
}else{
res.writeHead(404,"Resource not found", contentTypeHTML);
res.write(html);
}
if(resEnd){

@@ -20,18 +43,30 @@ res.end();

exports.send405 = function(req, res, resEnd=true){
exports.send405 = function(req, res, html = "", resEnd=true){
// Method not supporetd ie. GET, POST others not supported
res.writeHead(405,"Method not supported", contentType);
res.write(JSON.stringify({"data" : "Method not supported"}));
if(resEnd){
res.end();
}
if (html == ""){
res.writeHead(405,"Method not supported", contentTypeJSON);
res.write(JSON.stringify({"data" : "Method not supported"}));
}else{
res.writeHead(405,"Method not supported", contentTypeHTML);
res.write(html);
}
if(resEnd){
res.end();
}
}
exports.send413 = function(req, res, resEnd=true){
exports.send413 = function(req, res, html = "", resEnd=true){
// Requesting for large data, not supported
res.writeHead(413, "Request too large", contentType);
res.write(JSON.stringify({"data" : "Request too large"}));
if(resEnd){
res.end();
}
if(html == ""){
res.writeHead(413, "Request too large", contentTypeJSON);
res.write(JSON.stringify({"data" : "Request too large"}));
}else{
res.writeHead(413, "Request too large", contentTypeHTML);
res.write(html);
}
if(resEnd){
res.end();
}
}

@@ -1,3 +0,3 @@

let contentType ={"Content-Type" : "application/json"}
var contentTypeJSON ={"Content-Type" : "application/json"}
var contentTypeHTML = {"Content-Type" : "text/html"};
/*

@@ -9,9 +9,15 @@ ==================

exports.send500 = function(req, res, err, resEnd=true){
exports.send500 = function(req, res, err, html="", resEnd=true){
// on error
res.writeHead(500, "Internal error occured", contentType);
res.write(JSON.stringify({"data" : "Internal error occured: " + err}));
if(resEnd){
res.end();
}
if(html== ""){
res.writeHead(500, "Internal error occured", contentTypeJSON);
res.write(JSON.stringify({"data" : "Internal error occured: " + err}));
}else{
res.writeHead(500, "Internal error occured", contentTypeHTML);
res.write(html);
}
if(resEnd){
res.end();
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc