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 doesn't accept solution #78

Closed ajvish closed 8 years ago

ajvish commented 9 years ago

Big time noob here. Here is the code:

*var express = require('express') var path = require('path') var app = express() app.use(require('stylus').middleware( process.argv[3] + "/.styl" )) app.get('/main.css', function(req, res) { res.end() }) app.listen(process.argv[2])**

main.css is being generated, but the GET doesn't fetch it. Please help!

marocchino commented 9 years ago

you don't need to get /main.css just serve it as static file.

ajvish commented 9 years ago

Tried that. But it says Cannot GET /main.css. :/

marocchino commented 9 years ago

Did you serve main.css file after create it?

ajvish commented 9 years ago

@marocchino Yeah. I think that's what the http.get() is for right?

First, I convert the .styl file into main.css using *app.use(require('stylus').middleware( process.argv[3] + "/.styl" ))**

After main.css is created, I serve it using: app.get('/', function(req, res) { res.end() }) app.listen(process.argv[2])

Correct me if I am wrong, but is this the way to do this?

nelsonlho commented 8 years ago

type in: sudo expressworks verify yourprogramname.js

azat-co commented 8 years ago

you're missing static middleware

app.use(express.static(FOLDERNAME))
PrinceOfShapeir commented 8 years ago

I keep getting "stylus.middleware is not a fuction."

azat-co commented 8 years ago

@PrinceOfShapeir did you install stylus? issues are not for help. they are for bugs in the workshop.

ar2pi commented 8 years ago

For anyone still trying to complete this, here's a solution that works:

var express = require('express');
var app = express();

app.use(express.static(process.argv[3]));
app.use(require('stylus').middleware(process.argv[3]));

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

Problem is that when running that piece of code, the "expected" answer is:

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

And when running the command with sudo it seems the "expected" answer is the right one but somehow the "actual" response is Cannot GET /main.css

SO, this is definitely a bug.

PS: If you yet wish to mark the exercise as "completed" you can still just validate it with this for normal user:

var express = require('express');
var app = express();

app.use(express.static(process.argv[3]));
// app.use(require('stylus').middleware(process.argv[3]));

app.get('/main.css', function (req, res) {
    res.end('Error: EACCES, open &#39;/usr/local/lib/node_modules/expressworks/exercises/stylish_css/public/main.css&#39;<br> &nbsp; &nbsp;at Error (native)\n')
})

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

And with this for sudo user:

var express = require('express');
var app = express();

app.use(express.static(process.argv[3]));
// app.use(require('stylus').middleware(process.argv[3]));

app.get('/main.css', function (req, res) {
    res.end('p {\n  color: #f00;\n}\n')
})

app.listen(process.argv[2]);
azat-co commented 8 years ago

@decksterr i think you installed some modules with sudo, remove your node_modules and any related modules up the folder tree and try again.

SharmaBiswadev commented 6 years ago

var express=require('express'); var app=express(); app.use(require('stylus').middleware(process.argv[3] || path.join(dirname, 'public'))) app.use(express.static(process.argv[3] || path.join(dirname, 'public'))); app.listen(process.argv[2]);

This worked well for me

meta-karan-bhargava commented 3 years ago

In case, anyone still reaches to end of this post, a gentle reminder to have a look at this line given in Hints: Remember that middleware is executed in the order app.use is called!

We have to serve css file first, so use stylus middleware accordingly.

Thanks!