Nodeparse - A lightweight, vanilla replacement for Express framework when parsing the HTTP body's data or parsing the URL parameters and queries with NodeJS.

Related tags

Database nodeparse
Overview

nodeparse

nodeparse-image

npm version install size npm downloads

A lightweight, vanilla replacement for Express framework when parsing the HTTP body's data or parsing the URL parameters and queries with NodeJS.

Installing

Using npm:

$ npm install nodeparse

Using

You first need to import the module.

const NodeParse = require("nodeparse");

Create a basic NodeJS http server, create nodeparse instance and init() it.

const http = require("http");
const NodeParse = require("nodeparse");

const server = http.createServer(function (req, res) {
	const nodeparse = new NodeParse(req, res);
	nodeparse.init();	
});

server.listen(port, function (error) {
	if (error) throw error;
	console.log("Server is running on port ", port);
});

Parsing url params

In order to parse the URL params. You need to make sure it inside the if (nodeparse.params) because of the favicon.ico return undefined.

const server = http.createServer(function (req, res) {
	const nodeparse = new NodeParse(req, res);
	nodeparse.init();

	if (req.method === "GET") {
		if(nodeparse.params) {
			console.log(nodeparse.params);	// => This will return an array of params.
			/*
				https://localhost:3000/api/products
				
				return => ["api", "products"]
			*/
		}
	}
});

Parsing url queries

For url queries.

const server = http.createServer(function (req, res) {
	const nodeparse = new NodeParse(req, res);
	nodeparse.init();
	
	if (req.method === "GET") {
		if (nodeparse.params) {
			console.log(nodeparse.queries); // => This will return an object of queries.
		}
		/*
			https://localhost:3000/api/products?name=banana&size=xl

			return => {"name": "banana", "size": "xl"}
		*/
	}
});

Parsing the http data

Because nodeparse.data is a promise return from req.on() so you need to await with nodeparse.data inside an async function.

const server = http.createServer(async function (req, res) {
	const nodeparse = new NodeParse(req, res);
	nodeparse.init();

	if (req.method === "POST") {
		console.log(await nodeparse.data);
	}
});

Built-in method

Nodeparse has some built-in method, in stead of using:

if (req.url === "/api/products" && req.method === "GET") {
	funtionToBeTriggered(res);
}

You can use this:

nodeparse.isRoute("api/products", "GET", functionToBeTriggered);

Credits

nodeparse is inspired by express when developers have to deal with params, queries and data with NodeJS.

License

MIT

You might also like...

Composable data framework for ambitious web applications.

Orbit Orbit is a composable data framework for managing the complex needs of today's web applications. Although Orbit is primarily used as a flexible

Dec 18, 2022

Create flexible REST endpoints and controllers from Sequelize models in your Express app

Finale Create flexible REST endpoints and controllers from Sequelize models in your Express or Restify app. This project aims to be a Sequelize 4.x an

Oct 18, 2022

A back-end server aplication created using node.js, express and mongodb.

Course Material and FAQ for my Complete Node.js, Express and MongoDB Bootcamp This repo contains starter files and the finished project files for all

Jan 4, 2022

Código desenvolvido na mentoria do Hiring Coders utilizando Express e GraphQL

hiringcoders-graphql Código desenvolvido na mentoria do Hiring Coders utilizando Express e GraphQL Contribuições A ideia do repositório é continuar si

Dec 29, 2022

Repository with various templates using nest ( express )

A progressive Node.js framework for building efficient and scalable server-side applications. Description Nest framework TypeScript starter repository

Nov 27, 2022

ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used

Jan 3, 2023

NodeJS PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more.

Node Postgres Extras NodeJS port of Heroku PG Extras with several additions and improvements. The goal of this project is to provide powerful insights

Nov 14, 2022

E-Commerce Application developed with nodejs and stored to mongodb.

E-Commerce Application This Application has been developed with nodejs and mongodb. Environment Variables Create a file named config.env in config dir

Dec 23, 2021

This is a demo sample of linking NODEJS via ORM and MYSQL

Demons(Demo of Nodejs with SQL) This is a demo sample of linking NODEJS with ORM and MYSQL Connecting Node to SQL is a hard task and not much help is

Apr 14, 2022
Releases(release)
Owner
Trần Quang Kha
Hello, My name is Kha and I am currently a senior student studying at University of Information and Technology. I'm currently chasing full stack.
Trần Quang Kha
This is a boilerplate for Nodejs (Nestjs/typescript) that can be used to make http server application.

Hexagonal architecture Table of Contents Overview Code architecture source code Service build information Regular user Advanced user Deployment Helm K

Moeid Heidari 20 Sep 13, 2022
Validate and auto-generate TypeScript types from raw SQL queries in PostgreSQL.

SafeQL Write SQL Queries With Confidence • Get started Install I would first recommend follow the instructions in the documentation. npm install --sav

null 747 Dec 28, 2022
Conjure SQL from GraphQL queries 🧙🔮✨

Sqlmancer Conjure SQL from your GraphQL queries ?? ?? ✨ ⚠️ This project is currently on hiatus. I am hoping to resume working on Sqlmancer once I have

Daniel Rearden 132 Oct 30, 2022
StashQL is a light-weight, open-source npm package that improves the speed of your GraphQL queries in your application.

Table of Contents What is StashQL? Install Getting Started Queries Mutations refillCache clearRelatedFields Logging The Team What is StashQL? StashQL

OSLabs Beta 67 Sep 30, 2022
Run SPARQL/SQL queries directly on Virtuoso database with connection pool support.

?? virtuoso-connector Package that allows you to create a direct connection to the Virtuoso database and run queries on it. Connection can be used to

Tomáš Dvořák 6 Nov 15, 2022
NodeJS,express and mysql starter project

Node-express-mysql-starterproject NodeJS,express and mysql starter project Start with cloning the repo & Run npm i to download all the dependecies Aft

Nermine slimane 16 Dec 11, 2022
Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express.

Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express.

Jared Hanson 5 Oct 11, 2022
HLS, DASH, and future HTTP streaming protocols library for video.js

videojs-http-streaming (VHS) Play HLS, DASH, and future HTTP streaming protocols with video.js, even where they're not natively supported. Included in

Video.js 2.2k Jan 5, 2023
AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Andrey Gershun 6.1k Jan 9, 2023
Azure Data Studio is a data management tool that enables you to work with SQL Server, Azure SQL DB and SQL DW from Windows, macOS and Linux.

Azure Data Studio is a data management tool that enables working with SQL Server, Azure SQL DB and SQL DW from Windows, macOS and Linux.

Microsoft 7k Dec 31, 2022