Closed ajvish closed 8 years ago
you don't need to get /main.css
just serve it as static file.
Tried that. But it says Cannot GET /main.css. :/
Did you serve main.css file after create it?
@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?
type in: sudo expressworks verify yourprogramname.js
you're missing static middleware
app.use(express.static(FOLDERNAME))
I keep getting "stylus.middleware is not a fuction."
@PrinceOfShapeir did you install stylus? issues are not for help. they are for bugs in the workshop.
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 '/usr/local/lib/node_modules/expressworks/exercises/stylish_css/public/main.css'<br> 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 '/usr/local/lib/node_modules/expressworks/exercises/stylish_css/public/main.css'<br> 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]);
@decksterr i think you installed some modules with sudo, remove your node_modules and any related modules up the folder tree and try again.
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
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!
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!