Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@somnusjs/somnus
Advanced tools
Readme
Minimal, database-agnostic REST API Framework based on Restify
Somnus is a very thin layer wrapping around the Restify Node.js library. It aims to set up foundational features of a web/API framework by adding (sometimes opinionated) out-of-the-box configurations on top of the bare-bone Restify. In short, it helps you:
console.log
which seems convenient at first but eventually will turn your project into a messWhile the original developer's intention is to add commonly essential features on top of Restify, it's also important to note that the key principal is to keep the codebase as small as possible, living up to Restify's standard of being a lighter library than the colossus we have in Express.js. Please keep this in mind should you decide to contribute to Somnus!
Somnus strongly promotes the use of next-gen JavaScript (ES6, ES7, etc.). Hence, it will most likely always enforce the latest LTS version of Node.js (for example 10.14.2
at writing time). Besides, it encourages the use of modern JS features such as arrow functions, const identifier and others (where they make sense).
Starting v8.2.0, somnus has Nginx Unit integration support. If you fail to install Unit's language module for Node.js (npm i unit-http
), be sure to follow up Unit's installation guide itself first. For example, MacOS users may want to follow the homebrew guide.
With Node.js and npm installed, simply run:
# installs a production build of this framework from the global npm repo
npm install somnus
Note: this section is only for contributors. If you only need to use Somnus, the installation step above is enough.
You can build the framework yourself by checking out this repository, cd
ing into it then running the build
or build:prod
npm script, for example:
# installs the toolchains needed for the build process
npm install
# outputs a development build into `lib/`
npm run build
# or if you want a production build
npm run build:prod
TBA: explain the difference between development and production builds
import somnus from 'somnus';
// or const somnus = require('somnus').default;
// you can add routes via the standard syntax
// as you would normally do with `express` or `restify`
somnus.server.get('/echo', (req, res) => res.send('echo echo'));
// or you can add routes by declaring a `routeConfig` object,
// which is then passed into `somnus.start()`
const routeConfig = {
'get /hello': (req, res) => res.send('world')
}
somnus.start({ routeConfig });
// from now on, all routes added above are available. Go ahead and test these
// paths with `curl` or your favourite web browser:
// - `/echo`
// - `/hello`
Support for NGINX Unit is available starting from somnus@8.2.0
. To use your somnus
-based application with Nginx Unit, you need to:
unit-http
module is installed (npm i -g unit-http
). Nginx recommends a global installation of this module
cd
into your existing somnus
-based application (where somnus
is at least at v8.2.0)unit-http
into your application (npm link unit-http
) (as instructed here)#!/usr/bin/env node
on top of the entry file of your app
webpack.BannerPlugin
like so: new webpack.BannerPlugin({ banner: "#!/usr/bin/env node", raw: true })
, as shared in this SO answer.chmod +x /path/to/your/entry.js
)and voilà, you can start it up with NGINX Unit as instructed in this tutorial
UNIX_SOCKET
: the unix socket at which the underlying http
server listens, defaults to undefined
, taking precedence over HOST
and PORT
(explained below) when definedHOST
: the host at which the underlying http
server listens, defaults to localhost
PORT
: the port at which the underlying http
server listens, defaults to a random available port on your systemLOG_LEVEL
: enum of bunyan log levels. If set, this will overwrite the default value, which is warn
for production build and debug
for development build.TARGET_DIST_BUILD
: only used when running tests. If true, the tests are run against the build artifact (lib/somnus.js
); otherwise, the source file (src/somnus.ts
)For those loving TypeScript: type-def for Somnus is backed directly into the build artifact so you don't have to install anything else. If your IDE somehow doesn't pick up the definitions automatically, please manually check/import the node_modules/somnus/lib/somnus.d.ts
file.
Also, as Somnus bases itself on Restify, you may benefit from installing @types/restify
and @types/restify-errors
in addition (Somnus doesn't bake them in for you).
The following command will run all tests found under ./test
and its subdirectories:
npm test
Why do we run tests for both src
and lib
directories? Because as library authors, we're responsible for ensuring that the build process transpiles & outputs as it should, and the best way to do that is by testing the code from both source and dist.
import somnus, { RouteConfig } from "somnus"
import somnus, { IRouteConfig } from "somnus"
somnus
is designed to be just a thin wrapper around restify
, starting v8, its major version will always match that of restify
. Please consult the corresponding Restify migration guide for breaking changes regarding Restify internal itself.Familiarity with the Restify library is recommended, though not necessarily to get you started with and profit from Somnus.
Practicality, Productivity, Simplicity, Fun (well, hopefully)
Somnus is latin for Sleep (or at least that's what Google told the developer). What better fits an API framework created for REST(ful) communications?
Somnus is aimed to make mundane day-to-day web/API development tasks as effortlessly fun as possible while maintaining the smallest codebase possible. Well, at least that's the original intent of the developer, so if you're considering contributing (which is a beautiful thing), please adhere to the said philosophy!
SQL
, MongoDB
, RethinkDB
and a plethora of other database solutions have made it easier and more fun than ever before to play with data. At the same time, it gives framework developers a hard time deciding on any database technology to go with and invest in. Somnus is aimed to make things simple and minimal, not to magnify what's already clunky enough. Hence, it's up to Somnus users to choose the database technologies they feel most suitable to their projects.
In fact, Somnus isn't developed with any database driver built-in. It's essentially the C in MVC.
Currently, there is no formal contribution guide. It probably makes sense to start there!
FAQs
Minimal, database-agnostic REST API Framework based on Restify
We found that @somnusjs/somnus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.