var express = require('express'),
app = express();
app.listen(process.env.PORT || 8080);
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
console.log(req.query); // _GET {}
});
app.get('/:param1', function(req, res) {
console.log(req.params); // {param1: ""}
});
app.get(/^(.*)$/, function(req, res) {
console.log(req.params); // []
});
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'twig');
// This section is optional and can be used to configure twig.
app.set('twig options', {
strict_variables: false
});
// Twig cache
Twig.cache(false);
});
app.get('/', function(req, res) {
res.render('index', {
param1: 'data'
});
});
app.use(function(req, res) {
res.status(404);
res.render('404', {
title: "404 - Page Not Found"
});
});
app.use(function(error, req, res, next) {
res.status(500);
res.render('500', {
title: "500 - Internal Server Error",
error: error
});
});
app.configure('development', function() {
app.use(express.errorHandler({
dumpExceptions: true, // Show Throw
showStack: true // Show file & line bug
}));
});
app.configure('production', function() {
app.use(express.errorHandler());
});
set NODE_ENV=production
exec sudo -u some-user NODE_ENV=production
app.listen(process.env.PORT || 8080);
// app.js
var myModule = require('./myModule.js');
console.log(myModule.test()); // 'test 01'
// myModule.js
export.test = function() {
return 'test 01'
}
export = function MaClass() {
// TODO
}