Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:12:05+00:00 2026-05-31T20:12:05+00:00

Coming from express.js, I want to give flatiron a try for a small project.

  • 0

Coming from express.js, I want to give flatiron a try for a small project. However, there are some small problems which keep me from actually getting somewhere.

var flatiron = require('flatiron')
,  session = require('connect').session
,  ecstatic = require('ecstatic')
,  path = require('path')
,  fs = require('fs')
,  plates = require('plates')
,  director = require('director')
,  winston = require('winston')
,  union = require('union');

var router = new director.http.Router();
var server = union.createServer({
  before: [
    ecstatic(__dirname + '/public')
  ]
});

router.get('/', function () {
  var self = this;
  fs.readFile('public/layout.html', 'utf-8', function(err, html) {
    [...]
  })
});

server.listen(3000, function () {
  console.log('Application is now started on port 3000');
});

How does routing with director work? When I leave ecstatic out, I can define routes like ‘/’ and it works, but then I don’t get static CSS and JS content. With ecstatic / is replaced with ‘index.html’ and ecstatic has priority over all defined routes.
– It’s the same behavior with connect-static. Route (/) is replaced by index.html.

I also tried a different approach using the connect middleware, which doesn’t work:

var flatiron = require('flatiron')
,  connect = require('connect')
,  path = require('path')
,  fs = require('fs')
,  plates = require('plates')
,  app = flatiron.app;

app.use(flatiron.plugins.http);
app.use(connect.favicon());
app.use(connect.static(__dirname + '/public'));
app.use(connect.directory(__dirname + '/public'));
app.use(connect.cookieParser('my secret here'));
app.use(connect.session({'secret': 'keyboard cat'}));

app.router.get('/', function () {
  console.log("GET /");
  var self = this;
  fs.readFile('public/layout.html', 'utf-8', function(err, html) {
    [...]
  })
});

app.listen(3000, function () {
  console.log('Application is now started on port 3000');
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:12:06+00:00Added an answer on May 31, 2026 at 8:12 pm

    I think the best answer for your question about routing in flatiron is, as always, inside the source code:

         app.server = union.createServer({
               after: app.http.after,
               before: app.http.before.concat(function (req, res) {
                 if (!app.router.dispatch(req, res, app.http.onError || union.errorHandler)) {
                   if (!app.http.onError) res.emit('next');
                 }
               }),
               headers: app.http.headers,
               limit: app.http.limit
         });
    

    As you can see here flatiron binds router as the last request handler, that is called after all middleware. If you place ‘ecstatic’ in app.http.before and it will be dispatched during workflow, no other middleware would be called.

    Your second block of code demonstrates that you don’t undestand difference between Flatiron’s .use() method from Express/Connect’s. I’ll try to make it clear on this example:

        flatironApp.use({
            // plugin object
            name : "pluginName"
          , attach : function(options) {  
              /*code*/  
          }
          , init : function(done) { 
              /*code*/ 
              done(); 
          }
        })
    
        connectApp.use(function(req, res, next) {
          /* code */
          next();
        })
    

    If you want to use Connect’s middleware in Flatiron you should place it respectively in app.http.before array like this:

        // Initiating application
        app.use(flatiron.plugins.http);
    
        // Adding request handlers
        app.http.before.push( connect.favicon() );
        app.http.before.push( ecstatic(__dirname + '/public') );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm coming from Eclipse, working in Visual Studio 2008 Express and just want to
I want to compress responses coming from my IIS Express driven web application. We're
Coming from a PHP background, I'm used to writing small functions that return a
Coming from PHP with some Java Struts 2.0 experience any tips/tricks on learning GWT?
Coming from a Java and C background, grasping some concepts of Ocaml has been
I am planning to do some extra coding at home on a project from
Coming from an RDBMS background, I was always under the impression Try as hard
Coming from Java programming, I'm used to the general Main<->Test Maven-setup for a project.
coming from .Net world, just want to know what is the corresponding collection to
Coming from ASP.NET Webform and Classic ASP. I want to know what are the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.