Teo.js
Please, meet yet another Node.js based web-framework.
Installing the framework
NPM
npm install teo.js -g
Clone git repo
git clone https://github.com/Antyfive/teo.js.git
Setup
Config
So, how to create config, which will be applied to your app?
In home directory of your application, just create config
directory, and place inside your *.js
file.
Here is default set of currently available properties:
protocol: "http",
host: "localhost",
port: 3000,
delimiters: '{{ }}',
compressOutput: false,
cache: {
"static": false,
"response": false
},
appDirs: ["models", "controllers"],
appFiles: ["app.js"]
Also, config is allowed to be splitted into development & production modes. Here is example of config for the test application:
module.exports = {
"production": {
protocol: "http",
host: "localhost",
port: 3000,
cache: {
"static": true,
"response": true
}
},
"development": {
protocol: "http",
host: "localhost",
port: 3100,
cache: {
"static": false,
"response": false
}
},
delimiters: '{{ }}',
compressOutput: true
};
Project structure
apps/-|
| your_app_dir/--|
| config/
| controllers/
| models/
| public/
| views/
| app.js // adittional app.js for your extra logic
node_modules/
app.js
App structure explained
Config
Place your *.js configs inside. Example of config you can see above.
Controllers
Directory is used for controllers.
Lets take a look what we can do inside the controller:
module.exports = function(client, db) {
console.log( "Index controller was initialized!" );
client.get("/my/url/:id", function(req, res) {
res.render("index", {
partial: {
id: "myid"
},
title: "Title"
}, function() {});
});
client.get("/json/:id", function(req, res, next) {
res.json({ id: req.params.id, 'title': "title" });
});
client.get("/:id/:title", function(req, res, next) {
next({ id: req.params.id, "title": req.params.title });
});
client.get("/get/news.json", function(req, res) {
res.send({ id: 1, title: "title" });
});
client.get("/get/error/404", function(req, res) {
res.send(404);
});
};
Basically, urls parsing is implemented in well-known express
style.
To be continued...