@junaidprodeveloper/press
v1.0.2
Published
Press is made specially to create or handel requests with ease
Maintainers
Readme
Press 🚀
A lightweight, zero-dependency Node.js HTTP routing framework modeled after Express. It simplifies standard http.createServer handling by providing an intuitive API for GET and POST routing along with automatic response serialization.
Features
- Zero Dependencies: Built entirely on top of the native Node.js
httpmodule. - Smart Responses: Automatic handling of
JSONobjects andHTML/textstrings via a customres.send()method. - Simple Routing: Explicitly register
GETandPOSThandlers with intuitive methods. - Custom 404 Pages: Automatic fallback for unhandled routes.
Installation
Install the package directly from the npm registry using your terminal:
npm install pressQuick Start
Import the package and spin up a lightweight server in just a few lines of code:
const Press = require('@junaidprodeveloper/press');
const app = Press();
const PORT = 3000;
// 1. Sending an HTML/Text string response
app.get('/', (req, res) => {
res.send('<h1>Welcome to Press Framework!</h1>');
});
// 2. Sending an automatic JSON object response
app.get('/api/user', (req, res) => {
res.send({
id: 1,
name: "Junaid",
status: "Active"
});
});
// 3. Handling POST data
app.post('/api/data', (req, res) => {
res.send({ message: "Data received successfully" });
});
// Start the server
app.done(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});API Reference
Press()
Initializes and returns a new instance of the router application server.
app.get(path, callback)
Registers a request handler for a given path matching the HTTP GET method.
- path (String): The targeted URL endpoint (e.g.,
'/about'). - callback (Function): Executed when the path matches. Receives native Node.js
reqand extendedresarguments.
app.post(path, callback)
Registers a request handler for a given path matching the HTTP POST method.
app.done(port, callback)
Starts the underlying HTTP infrastructure server to listen for incoming client traffic.
- port (Number): Network port allocation.
- callback (Function): Optional function fired upon successful server boot.
res.send(body)
An added extension method available natively inside your route callbacks.
- Automatically sets header
Content-Type: application/jsonif an object is passed. - Automatically sets header
Content-Type: text/html; charset=utf-8if a raw string is passed.
License
ISC
