This project started about a year ago when I was looking for a great boilerplate setup for a NodeJS application. I was coming from the Rails community and was hoping that someone would have created something like Rails in NodeJS.
I started building a whole slew of NodeJS applications and kept a boilerplate project on the side where I would store all of the best practices I had learned. That boilerplate became pretty large, monolithic, and opinionated, which were all of the things that I had hated about working with a run-of-the-mill Rails application. (Yes, I know there are ways of modularised Rails apps, but let's be honest with ourselves: most Rails apps, even those written by companies, are big, monolithic nightmares.)
So, after studying software modularity and the UNIX philosophy, reading a slew computer science research papers, and speaking with members of the NodeJS community, I have decided to ditch the whole boilerplate idea and instead break up all the best practices I have learned into independent modules. The point of these modules are to capture everything I learn on my journey as a software developer.
Cthulhu is just the server portion, packed with all the stuff that I wish, and I'm sure many other people wished as well, had come with the Express server.
process.cwd(). You can now run multiple
Cthulhuinstances within the same directory.
middleware.cors. I suggest using cors as if provides really dynamic configuration options. Possibly might add this in by default and allow users to pass in their configuration in
cthulhu.configurebut not entirely sure yet.
var cthulhu = ;var cors = ;cthulhu;cthulhu;
npm install cthulhu --save
var app =app;
var router = app;router;app
var app =// ...lusca:csrf: true// etc.// ...
I chose to use the Lusca module for security because if it's secure enough for PayPal than it's secure enough for me.
Swig is used by default, but you can change this to use the view engine you prefer by not providing a
views options in
.configure() and specifying the
views settings in the same way you would any express application.
var app =// ...log:dir: pathfile: 'all-logs.log'// ...;applogger;applogger;
The example above will add a logger to
app;// NOTE: The directory './logs' must exist in order// for the 'some-logs.log' file to be created.apploggerssomeLogger;
You can add a winston logger through the
app.addLogger API. As its first argument it takes a
String which is the path to the file you want to log to. You can also pass a config object as the second parameter like so:
var app =// ...mailer:service: 'gmail'username: 'firstname.lastname@example.org'password: 'foobarbaz'// ...;
Providing a mailer configuration will allow you to send emails, using nodemailer, through
app.mailer. If you don't provide a mailer configuration,
app.mailer will simply not be available.