lethil
v1.3.14
Published
...a minimal and configurable Node.js web framework!
Downloads
122
Maintainers
Readme
Lethil
...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