pikanen
v1.0.1
Published
a simple Express server, configurable from the command line (quick mocking tool). Generates an index file with express and serves it. Nothing you haven't seen before
Downloads
2
Readme
Pikanen
(Pikanen is finnish for ~quickie)
This is a very barebones Express server bootstrapper.
Similar to many quickstart servers, but with only a few dependencies and no extra bells or whistles.
Pikanen also generates a readable simple express index file, named pikanen-index.js
, so it doubles as a simple express server generator.
All loose (no leading dashes) keywords are treated as directory paths, relative to current location.
Unknown dashed keywords raise errors.
Installation
pikanen
is a node executable, install globally with npm install -g pikanen
.
Usage
So, you have a new idea for a web feature that requires a server. Maybe a javascript framework is needed, so you have to serve the static app fragments/templates/whatever, and they all reside inside a www folder.
Pikanen is a simple tool for not having to look up an express tutorial for the basic setup every time you need to just get a very basic server up.
In the above situation, invoking pikanen www
will create a basic node express server file for the specified directory
Oh no!
You will still need to install express in your project folder via npm i express
, after which, invoking pikanen will yield the called for result:
Success! You are now serving the contents of the directory at localhost:3000/www
, as well as having created a file pikanen-index.js
in the folder where you invoked the command, which can be used as a basis for more complex routing logic without having to look up the same Express tutorial boilerplate for the 100th time.
Parameter options:
Basic usage:
$ pikanen www
serves /www
from current directory at localhost:3000/www
Multiple directories:
$ pikanen www libs
serves both/www
and/libs
from current directory underlocalhost:3000/www
andlocalhost:3000/libs
Port: -p/--port
$ pikanen -p 8001 www
serves/www
from current directory atlocalhost:8001/www
.
aliases:
- Aliasing allows you to set aliases for directories with unwieldy names or long relative paths, like UI components inside a node_modules directory
$ pikanen /=node_modules/something/www
serves directory/node_modules/something/www
atlocalhost:3000/
.
Root: -r/--root
- should probably be called publicRoot or something, and allow the reverse too
$ pikanen -r api/v1 www
serves directory/www
atlocalhost:3000/api/v1/www
. The root option changes the root of the whole server.
Silent: -s/--silent
$ pikanen -s www
only creates the file without starting up the resulting servers
Configuration
The package can also run off a configuration placed in the local package.json
file.
{
"pikanen":{
"silent":"false",
"paths":["/=www", "assets=node_modules/somelib/dist"],
"port":3001,
"root":"/api"
}
}
When you call pikanen
in this directory, it will extract the configuration from package.json and use the variables set there.
Passed command line arguments will override the settings in the package.json
, except paths, which will concatenate with the ones in the package file: