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 8928201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:22:57+00:00 2026-06-15T08:22:57+00:00

Here’s what I want. A node application using the express webserver Using coffeescript on

  • 0

Here’s what I want.

  • A node application using the express webserver
  • Using coffeescript on the server and more importantly the client
  • Using require.js on the client (and eventually on the server)

The recommended way I’ve been able to find of hooking up coffeescript for the client is to use connect-assets. This seems to require using jade helpers to actually compile coffeescript eg.

!=js('monalisa.js')

seems to compile monalisa.coffee and generate the correct <script> tag. Now I want to use require.js and here I stumble. How do I ensure that connect-assets compiles everything correctly without using the jade helpers?

Here’s my fairly simple app.js:

require('coffee-script');

var express = require('express')
  , http = require('http')
  , path = require('path')
  , connectAssets = require('connect-assets');

var publicDir = path.join(__dirname, 'public');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');

  app.use(express.favicon());
  app.use(express.logger('dev'));

  app.use(express.bodyParser());
  app.use( connectAssets() );
  app.use('/public', express.static(publicDir));

  app.use(express.logger());
  app.use(express.methodOverride());
  app.use(app.router);
});

app.configure('development', function(){
  app.use(express.errorHandler({
    dumpExceptions: true,
    showStack: true
  }));
});

app.get('/', require('./routes').index);
app.get('/monalisa', require('./routes/monalisa').monalisa);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});
  • 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-06-15T08:22:59+00:00Added an answer on June 15, 2026 at 8:22 am

    I’ve created a package to help solve this problem; it’s called connect-assets-jspaths.

    From the readme:

    Installation

    npm install connect-assets-jspaths

    • Note, there is a dependency on CoffeeScript.

    Server Side Usage

    assets = require "connect-assets"
    jsPaths = require "connect-assets-jspaths"
    
    # Snip ...
    
    app.use assets()
    # Exports the global function exportPaths() and jsUrl(); see below in View Helpers.
    jsPaths assets
    
    # Optionally, pass a log function to see progress
    # jsPaths assets, console.log
    

    Watch changes and re-compile

    Now you can pass some additional callbacks in and it will monitor your connect assets directories for changes.

    fileChangedCallback = (err, filePath) ->
        console.log "File Changed: #{filePath}"
    
    jsPaths assets, console.log, fileChangedCallback, (err, watcher) ->
        console.log "Watcher initialized"
    

    NOTE You’ll probably want to disable this for production mode.

    View Usage

    This module exports two global functions exportPaths() and jsUrl().

    // Using this in your view
    != exportPaths("jsPaths")
    
    // Turns into this when rendered in production
    <script type="text/javascript">
        var jsPaths = { "main", "/builtAssets/js/main.13819282742.js" /* snip all the other file paths */ };
    </script>
    
    
    // Using this in your view
    - var mainJsPath = jsUrl("/js/main.js")
    script(type="text/javascript", data-main="#{mainJsPath}", src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.0.2/require.min.js")    
    
    // Turns into this when rendered in production
    <script type="text/javascript" data-main="/builtAssets/js/main.13819282742.js" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.0.2/require.min.js"></script>
    

    Dynamic RequireJS Paths

    Now that we have a variable with our requireJS friendly paths in it, we can set those paths in the RequireJS config

    # Example main.coffee file in /assets/js folder
    
    requirePaths =
      paths:
        jquery: "//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min"
        underscore: "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min"
        backbone: "//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min"
        text: "/js/lib/text"
        handlebars: "/js/lib/handlebars"
    
    if jsPaths
      for own key, value of jsPaths
        # Fix up the lib references
        key = key.slice 4 if key.slice(0, 4) == "lib/"
        requirePaths.paths[key] = value 
    
    require.config
      paths: requirePaths.paths
    
      shim:
        jquery:
          exports: "$"
        underscore:
          exports: "_"
        backbone:
          deps: ["underscore", "jquery"]
          exports: "Backbone"
    
    require ['app'], (App) ->
        new App().initialize()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
here is my configuration: http://domain.com (obviously fictitious name...) hosted on a server running Apache
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here's what I'm doing. I want to upload multipart file via Ajax to my
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is my error(if you need any more info just ask)- Error SQL query:
Here's the two scenarios. We are using a manually built xml soap request with
Here's the situation, i want to have a user that can enter time on
here's a conundrum for you, Using Django 1.4, I cannot get messages set through
Here is the code from my project where I am using a datepicker. 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.