Intro π±βπ»
So first off, I just want to thank everyone that used my first and only NPM package I've ever created.
I pretty much abandoned the project after getting more experienced these past few years but today I decided I wanted to update this package and make it a little bit more useful.
How the original project came to be:
Late last night I decided to finally publish my very own npm package, it's something I've wanted to do for a while now and I could never decide what to package.
While brainstorming I was busy working on a node.js app to process some data, the same code I've used in several projects.
This was it, the perfect package. I don't like searching for stuff I've already used and will use again in the future so I decided to package my most used node functions into a lightweight npm package.
Link to the old version and legacy post: Node-Essentials
About Node-Essentials π±βπ
This is a nodejs toolkit for doing asynchronous REST API calls, writing files to the system, starting up express-js servers and more coming soon.
Setup π§
Run:
npm install node-essentials
And include it in your app:
const node = require('node-essentials');
or
import * as node from 'node-essentials';
Current Methods β
-
http - REST Requests.
-
helpers - Helper functions.
- distinct - Return a Distinct array.
-
server - Express server.
- start - Set-up a express-js server on the specified port and directory.
-
fileManager - Manage files.
- writeToFile - Writes anything passed through to storage as any file.
Quickstart
Simple Get
Want to quickly and easily retrieve data from an API?
executeGet(url: string, options?: any): Promise<any>
Implementation:
import http from 'node-essentials';
async function getData() {
const data = await http.executeGet("https://my-json-server.typicode.com/typicode/demo/db").then();
console.log(data);
}
Response:
{
posts: [
{ id: 1, title: 'Post 1' },
{ id: 2, title: 'Post 2' },
{ id: 3, title: 'Post 3' }
],
comments: [
{ id: 1, body: 'some comment', postId: 1 },
{ id: 2, body: 'some comment', postId: 1 }
],
profile: { name: 'typicode' }
}
Distinct
Want to easily return distinct values from an array?
distinct(array: Array[any]);
Implementation:
import helpers from 'node-essentials';
const nonDistinct = [1,1,1,2,3];
function getDistinct(){
const distinct = helpers.distinct(nonDistinct);
console.log(distinct);
}
Response:
[1,2,3]
Write To File
Want to write files to storage with data?
writeToFile(folder: string, fileName: string, extension: string, data: any);
Implementation:
import fileManager from 'node-essentials';
const data = {
sample: "Sample Data"
}
fileManager.writeToFile("./", "fileName", "json", JSON.stringify(data));
Conclusion π
The package contains functions I commonly use, I will be adding more simplified essential tools/functions as time goes on!
It's been an interesting journey making my first package and any feedback/suggestions of functions to add would be welcomed.
Where to get the package
Author
Node Essentials is Developed and Maintained by Nicolaas Nel
Made with π and β by Nicolaas Nel.
Top comments (0)