@minimajs/server v0.2.0
Introducing the groundbreaking HTTP framework for Node.js - an innovation tailored for the modern developer seeking efficiency, elegance, and speed. This framework is designed with a forward-looking mindset, embracing the latest advancements in JavaScript while prioritizing ease of use and performance.
Highlights
Functional Approach: Embracing the functional programming paradigm, this framework empowers developers to write clean, concise, and composable code, promoting modular design and scalability.
100% TypeScript: Built entirely in TypeScript, ensures type safety throughout the development process, reducing errors and enhancing code quality.
Mandatory ESM Adoption: mandates the adoption of ECMAScript Modules (ESM) over CommonJS, ensuring developers unlock the full potential of modern JavaScript features like root-level await, code splitting and more...
Instant Context Access: seamless access to request data like headers or body with functions like
getRequest()andgetBody()anywhere within the same request context. Say goodbye to tediousreq/resdrilling.No Boilerplate Needed: Bid farewell to boilerplate code. With its minimalist approach, eliminates unnecessary setup and configuration.
Getting started
Your project directory structure should look like this:
.
├── src
│ ├── index.ts // Entry point
│ └── user // User module
│ └── index.ts // User module entry point
└── package.jsonEnsure that your package.json file has the "type": "module" field to enable ECMAScript modules (ESM) support:
{
"name": "hello-nodejs",
"type": "module"
}Creating Your Application
import { createApp, getParam } from "@minimajs/server";
const app = createApp();
app.get("/:name", () => `Hello ${getParam("name")}!`);
await app.listen({ port: 1234 });This code creates a MinimaJS application with a single route handler for the root URL ("/") and a parameter name.
That's all!
Compiling and running your TypeScript project:
Using tsc Compiler
While you can compile your TypeScript code using the TypeScript Compiler (tsc) and then run the compiled JavaScript files, it might involve multiple steps. Here's how you can do it:
tsc src/*.ts --module NodeNext --moduleResolution NodeNext --outDir dist
node dist/index.jsServer listening at http://0.0.0.0:1234
curl http://0.0.0.0:1234/John
> Hello John!Using ebx Bundler
On the other hand, you can utilize the ebx bundler, known for its lightning-fast performance and seamless bundling experience tailored specifically for Node.js projects.
Read more https://npmjs.com/package/ebx
installing ebx
yarn add -D ebxAdd following inside your package.json file
{
"scripts": {
"dev": "ebx src/index.ts -wsr",
"build": "ebx src/index.ts",
"start": "node dist/index.js"
}
}With ebx, you can directly bundle and execute your TypeScript code in a single step, significantly reducing build times and simplifying your workflow.
To start your project in development mode.
yarn devTo build your project for production deployment, run:
yarn buildOnce your project is built, you can start the server using:
yarn startThis command runs the compiled JavaScript files in the dist directory.
See the full documentation https://minima-js.github.io/