Getting Started

Installing

Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory :)

$ mkdir myapp
$ cd myapp

Use the npm init command to create a package.json file for your application.

$ npm init

This command prompts you for a number of things, such as the name and version of your application. For now, you can simply hit RETURN to accept the defaults for most of them, with the following exception:

entry point: (index.js)

Enter app.js, or whatever you want the name of the main file to be. If you want it to be index.js, hit RETURN to accept the suggested default file name.

Now, install Minimaal in the myapp directory and save it in the dependencies list. For example:

$ npm install minimaal

To install Minimaal temporarily and not add it to the dependencies list:

$ npm install minimaal --no-save

Hello World

index.js
const minimaal = require("minimaal");
const app = minimaal();
const port = 3000;
 
app.get("/", (req, res) => {
  res.send("Hello World!");
});
 
app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

This app starts a server and listens on port 3000 for connections. The app responds with “Hello World!” for requests to the root URL (/) or route. For every other path, it will respond with a 404 Not Found.

The example above is actually a working server: Go ahead and click on the URL shown. You’ll get a response, with real-time logs on the page, and any changes you make will be reflected in real time.

Running Locally

First create a directory named myapp, change to it and run npm init. Then, install minimaal as a dependency.

In the myapp directory, create a file named app.js and copy the code from the example above.

The req (request) and res (response) are the exact
same objects that Node provides, so you can invoke req.pipe(),
req.on('data', callback), and anything else you would do without Minimaal involved.

Run the app with the following command:

$ node app.js

Then, load http://localhost:3000/ in a browser to see the output.