azat-co / expressworks

Learn Express.js from the author of one of the best books on Express.js—Pro Express.js— with this workshop that will teach you basics of Express.js.
MIT License
709 stars 220 forks source link

Stylish CSS - how do you make the CSS file #100

Closed bessieatrazoyo closed 8 years ago

bessieatrazoyo commented 8 years ago

I can’t figure out how to use the middleware to create the stylesheet. How do I use it?

This is my code:

var express = require("express");
var http = require("http");
var stylus = require("stylus");
var path = require('path');

var app = express();
app.set('views', process.argv[3]);

app.all("*", function(request, response, next) {
  // everything will come through here.
  console.log('REQUEST: ' + request.url+'\n'); // just to see
  next();
});

app.get("/main.css", function(request, response) {
//  var pathStyle = path.join(process.argv[3], "main.styl");
//  console.log('path = ' + pathStyle);
  console.log('main.css');
  response.end(app.use(
      stylus.middleware('main.styl')));
});

app.listen(process.argv[2]);

And this is what it outputs:

REQUEST: /main.css

main.css
/Users/razoyo-dev/NodeSchool/node_modules/express/lib/router/index.js:138
  debug('dispatching %s %s', req.method, req.url);
                                ^

TypeError: Cannot read property 'method' of undefined
    at Function.handle (/Users/razoyo-dev/NodeSchool/node_modules/express/lib/router/index.js:138:33)
    at EventEmitter.handle (/Users/razoyo-dev/NodeSchool/node_modules/express/lib/application.js:173:10)
    at ServerResponse.app (/Users/razoyo-dev/NodeSchool/node_modules/express/lib/express.js:38:9)
    at ServerResponse.g (events.js:260:16)
    at emitNone (events.js:72:20)
    at ServerResponse.emit (events.js:166:7)
    at finish (_http_outgoing.js:548:10)
    at afterWrite (_stream_writable.js:346:3)
    at doNTCallbackMany (node.js:461:18)
    at process._tickCallback (node.js:359:17)
azat-co commented 8 years ago

your code looks wrong on many levels...

here's how to use the static middleware http://expressjs.com/starter/static-files.html

azat-co commented 8 years ago

@bessieatrazoyo I recorded this video for you https://www.youtube.com/watch?v=UJ0QzpHOLec

pizzachip commented 8 years ago

I got sidetracked on another issue, but I promise I'll be back. Thank you.

bessieatrazoyo commented 8 years ago

Thank you so much for the video. It really helped.

This is about a little issue that I ran into:

When I did this:

   expressworks run program.js

I got this:

    p {
      color: #f00;
    }

When I did this:

    expressworks verify program.js

I got this nonsense:

Error: EACCES: permission denied, open &#39;/usr/local/lib/node_modules/expressworks/exercises/stylish_css/public/main.css&#39;<br> &nbsp; &nbsp;at Error (native)

The secret sauce was to do this:

    sudo expressworks verify program.js

I am on a Mac-Book