1.3.14 • Published 4 months ago

lethil v1.3.14

Weekly downloads
14
License
MIT
Repository
github
Last release
4 months ago

Lethil

Build Status Github npm-download-count npm Mocha

...lethil is a minimal and configurable Node.js web framework, it has no dependencies but customizable and allow developer to deploy multiply applications simultaneously, and which has a very minimum requirement and aim to provided as light as possible.

Please refer to Getting started for directories strucuture, dependencies guide and basic command-line for setup/task.

npm install --save lethil

... lethil is currently ECMAScript modules and expected to be import (esm) but not require.

How does it work

server

// serve.js
import core from 'lethil';

const app = core.server();
const config = app.config;

app.get('/', function(req, res) {
  res.send('Home')
});

app.get('/about', function(req, res) {
  res.send('About')
});

app.get('/none', function(req, res) {
  res.status(404).send('Not found');
});

app.get('/test/:id', function(req, res) {
  res.json(Object.assign({test:true},req.params,req.query));
});

app.get('/middleware', function(req, res,next) {
  setTimeout(next, 2000);
  // setTimeout(() => { next(); }, 1000);
},function(req, res) {
  res.send('Middleware...')
});

app.get('/get-file/:fileName', function(req, res) {
  res.setHeaders({
    "Content-Type": "application/json; charset=utf-8"
  });
  res.setHeaders("Content-Type", "application/json; charset=utf-8");

  const file = path.resolve(
    "my-storage/" + req.params.fileName
  );
  core.seek.readStream(file).pipe(res);
});

app.listen(config.listen, () => {
  console.log(config.name,app.address.address,app.address.port);
  // NOTE: app.close() helps mysql pool connection gracefully end.
  // app.close();
});
node serve

command

// run.js
import core from 'lethil';

const app = core.command();

app.get('/', function(req) {
  return 'Main';
});
app.get('/about', function(req) {
  return 'About';
});

app.get('/test/:id', function(req) {
  return req.params.id
});

app.execute(() => {
  app.close();
});

app.on('success',function(e) {
  console.log('...',e)
});

// NOTE: on error
app.on('error',function(e) {
  console.log('...',e)
});
node run
> Main
node run about
> About
node run test/123
> 123

License

MIT

1.3.14

4 months ago

1.3.13

4 months ago

1.3.11

4 months ago

1.3.12

4 months ago

1.3.10

4 months ago

1.3.9

5 months ago

1.3.7

7 months ago

1.3.6

8 months ago

1.3.8

7 months ago

1.3.5

10 months ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

2 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7-beta.2

3 years ago

1.1.7-beta.1

3 years ago

1.1.7-beta.0

3 years ago

1.1.7

3 years ago