xpress-shotgun is a npm module that shotguns an express MVC to your specified directory
-
a directory will be made along with the model, with methods and sql commands already embedded the controller & the views
-
you will have a full crud express app, all you have to do is create a database, a node server, & fll out views to your liking
-
shotgun also takes care of the npm init & installs ejs(viewengine) and pg-promise(more info below)
Bash version can be queried with the --version flag:
bash --version
output -> 3.2.53(1)-release
The actual installation is going to happen with HomeBrew, the OS X package manager, if you don’t have it, install it with the following command:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update homebrew packet database and install bash:
brew update && brew install bash
Add the new shell to the list of allowed shells
sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
Change to the new shell
chsh -s /usr/local/bin/bash
install shotgun GLOBALLY:
npm install -g xpress-shotgun
once installed run:
shotgun nameofapp dbname modelname(capital) controllername(plural) singularRESPONSE
"ejs": "^2.5.7",
"express": "^4.16.2",
"pg-promise": "^7.0.3"
PG-PROMISE grants you accesss to DB query methods
- Automatic connections
- Automatic transactions
- Powerful query-formatting engine
- Support for ES6 generators and ES7 async/await
- Declarative approach to handling query results
- Global events reporting for central handling
- Extensive support for external SQL files
- Support for all promise libraries
- Simple SELECT
db.any('SELECT * FROM users WHERE active = $1', [true])
.then(function(data) {
// success;
})
.catch(function(error) {
// error;
});
try {
const users = yield db.any('SELECT * FROM users WHERE active = $1', [true]);
// success
}
catch(e) {
// error
}
try {
const users = await db.any('SELECT * FROM users WHERE active = $1', [true]);
// success
}
catch(e) {
// error
}
Features
- Control flow with <% %>
- Escaped output with <%= %> (escape function configurable)
- Unescaped raw output with <%- %>
- Newline-trim mode ('newline slurping') with -%> ending tag
- Whitespace-trim mode (slurp all whitespace) for control flow with <%_ _%>
- Custom delimiters (e.g., use instead of <% %>)
- Includes
- Client-side support
- Static caching of intermediate JavaScript
- Static caching of templates
- Complies with the Express view system
<% if (user) { %>
<h2><%= user.name %></h2>
<% } %>
Try EJS online at: https://ionicabizau.github.io/ejs-playground/.
var template = ejs.compile(str, options);
template(data);
// => Rendered HTML string
ejs.render(str, data, options);
// => Rendered HTML string
ejs.renderFile(filename, data, options, function(err, str){
// str => Rendered HTML string
});