Skip to content

Latest commit

 

History

History
96 lines (65 loc) · 1.69 KB

Application.md

File metadata and controls

96 lines (65 loc) · 1.69 KB

Application | nodester

Barebones examples

const nodester = require('nodester');

const app = new nodester();

app.listen(8080, function() {
  console.log('listening on port', app.port);
});

With a database

const nodester = require('nodester');

const { buildConnection } = require('nodester/database/connection');
// Standard sequilize configuration:
// https://sequelize.org/docs/v6/getting-started/#connecting-to-a-database
const db = buildConnection({
  host: ...,
  port: ...,
  name: ...,

  username: ...,
  password: ...,

  dialect: ...,
  pool: ...,
  charset: ...,
  collate: ...,

  timestamps: ...,

  logging: ...,
});

const app = new nodester();
app.set.database(db);

app.listen(8080, function() {
  console.log('listening on port', app.port);
});

Extending Application functionality

Extending Instance (safe way):

const serveStatic = require('serve-static');

const nodester = require('nodester');

const app = new nodester();
app.extend('static', serveStatic);
app.static(<path_to_static_directory/>);

Short:

const serveStatic = require('serve-static');

const nodester = require('nodester');

const app = new nodester();
app.extend('static', serveStatic)(<path_to_static_directory/>);

Extending Class:

If you really want to override properties or use nodester as a boilerplate, you should extend the default application class:

const NodesterApp = require('nodester');

class MyApp extends NodesterApp {
  constructor(opts) {
    super(opts)
  }

  // Override everything you want here...
}

// Don't forget to export.
module.exports = MyApp;

Copyright

Copyright 2021-present Mark Khramko