NodeJS without NPM

NodeJS without NPM

Implementing a Web framework in NodeJS without using NPM

Faiz A. Farooqui's photo
Faiz A. Farooqui

Published on Aug 19, 2018

3 min read

This article lists things that we can achieve in NodeJS without using any NPM dependencies. You can find the repository on GitHub — faizahmedfarooqui/nodejs.

I will be noting down all the things that I could bring out using only low-level NodeJS APIs;

  1. RESTful API:

    • A server to listen to HTTP/HTTPS requests (View Code)
    • Deflate / GZIP Compression for HTTP/HTTPS created servers (View Code)
    • RESTful API to CRUD and many more for users, tokens & checks (View Code)
    • Router for request methods like GET, POST, PUT & DELETE (View Code)
    • Handlers(ie. controllers) to handle requests & their methods (View Code)
    • Model Base class (View Code)
  2. Workers:

    • A Worker to execute things in the background (View Code)
  3. Logging:

    • A logging logic that logs everything into a *.log file (View Code)
  4. Compress & Decompress:

    • A gzip compression logic which compresses older log file (View Code)
  5. Debugging:

    • Local debug environment for the developments in each file (View Code)
  6. Serve Routes & Templates:

    • A use of template logic & data interpolation (View Code)
  7. Serve Static Assets:

    • Logic to serve static assets to the web-app (View Code)
    • Web routes handler for serving pages & static assets (View Code)
  8. CLI Tool with Input Handlers & their Responders:

    • The CLI tool that runs using node’s readline, events libraries & many more (View Code)
    • CLI Events handlers (View Code)
    • CLI Events responders (View Code)
  9. Handling Error Crash:

    • Server request are handled using try-catch block & now rather than app crash send 500 error response (View Code)
  10. Debugger Mode:

    • For detailed information, please use its official documentation from NodeJS.
    • To run the app in debugger mode, use command node inspect index-debug.js
  11. Performance Hooks:

    • Added PerformanceObserver Node Class to observe all the entries & log them out to the CLI (View Code)
    • Added Performance Mark & Measure methods to measure all the marked performance steps (View Code)
    • To see how it works, run the command NODE_DEBUG=performance node index.js in your terminal
  12. Cluster:

    • Added a new file with clusters, here forks are created by the count of the CPUs available (View Code)
    • To see how it works, run the command node index-cluster.js in your terminal
  13. Child Process:

    • Using ls commands into the .logs folder from CLI commands list logs (View Code)
  14. Other NodeJS Modules:

    • Use of Async Hooks module (View Code)
    • Use of HTTP/2 module in Client & Server Logic (View Code)
    • Use of NET module in Client & Server Logic (View Code)
    • Use of REPL module (View Code)
    • Use of TLS/SSL module in Client & Server Logic (View Code)
    • Use of UDP module in Client & Server Logic (View Code)
    • Use of VM module (View Code)

# How to download & setup?

#
# You only need NodeJS (LTS) ie. >= 8.11.3
#

# Clone this repo using your terminal
git clone https://github.com/faizahmedfarooqui/nodejs.git;

# Go inside the repo
cd nodejs;

# Make a data directory into the root of the project
mkdir .data && cd .data;

# Create 3 more directories into the .data directory
mkdir users checks tokens;

# Go back to project's root 
cd ..;

# Make a logs directory into the root of the project
mkdir .logs;

# Goto the https directory
cd https;

# Now run the command given also available 
# in the file keyGeneration.txt
openssl req -newkey rsa:2048 -new -nodes -x509 \ 
 -days 3650 -keyout key.pem -out cert.pem;

That's All!


# About Me 👨‍💻

I'm Faiz A. Farooqui. Software Engineer from Bengaluru, India. Find out more about me @ faizahmed.in

 
Share this