Total Pageviews

Thursday, 12 November 2020

Vanilla Node Server

 

An example of a vanilla node server with both http & https.

Bootstrap for a vanilla Node.js server without Express so you can see how it works. Often it's tough weeding throug the many tutorials and blog posts out there for Express, Hapi, etc IMO, it's always better to learn the fundamentals of Node.js (...they are baked in!) which is often overlooked by developers and then move onto the libraries.

What this Repo Has to Offer

  • Everything in one file without modularization
  • Vanilla Node Server with http and https support
  • Standard err/callback pattern, no promises or asyncawait
  • As vanilla JS as possible, only ES6 syntax for arrow functions and template literals
  • Support for http & https
  • Config for NODE_ENV supporting dev, prod, staging
  • Basic Routing & Handling
  • Returns a response with empty object if no payload
  • No package.json :)

Start Server

  • Start node index.js
  • Start with NODE_ENV: NODE_ENV=production node index.js
  • Check to see if server is running:
     NODE_ENV=staging node index.js
     POSTMAN > localhost:3000/status
  • Stop Server: Ctrl + C

from https://github.com/ahadb/vanilla-node-server

No comments:

Post a Comment