Azat Mardanov's personal website: projects, books, links to social media profiles.
- Twitter Bootstrap
- Sumlime Text 2
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.
License: MIT License
Azat Mardanov's personal website: projects, books, links to social media profiles.
The proposed solution in good_old_form does not pass in my terminal. However, below is a working solution for all that it is worth:
var express = require("express");
var app = express();
var bodyparser = require("body-parser");
app.use(bodyparser.urlencoded({extended: false}));
app.get("/form", function(req, res) {
res.send(req.body.str.split('').revers().join(''));
});
app.listen(process.argv[2]);
It's always empty.
The official solution is:
var express = require('express')
var app = express()
app.get('/search', function(req, res){
var query = req.query
res.send(query)
})
app.listen(process.argv[2])
but it doesn't work.
My solution was:
var express = require('express');
var app = express();
app.get('/search', function (req, res) {
var query = req.query;
delete query.__proto__;
res.send(JSON.stringify(query));
});
app.listen(process.argv[2]);
I don't know if it's a good solution, but it worked.
This is the error output:
$ expressworks verify program.js
?exercises.HELLO WORLD!.compare.title || common.exercise.compare.title || compare.title?
/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/comparestdout.js:19
return new Array(sz + 1).join(ch)
^
RangeError: Invalid array length
at repeat (/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/comparestdout.js:19:10)
at center (/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/comparestdout.js:25:13)
at Exercise.transform (/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/comparestdout.js:57:40)
at Transform._read (/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at Transform._write (/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
at Transform.Writable.write (/home/ubuntu/.nvm/v0.11.14/lib/node_modules/expressworks/node_modules/workshopper-exercise/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
at Stream.ondata (stream.js:51:26)
at Stream.emit (events.js:107:17)
Thanks!
I'm using the exact same code as per the solution @ https://github.com/azat-co/expressworks/blob/master/problems/jade/solution.js
However, expressworks still deems this a fail:
The 'jade' package is also installed locally, and globally.
First of all, this is a great app! Thank you for putting this together.
This ran fine using Node v0.11.8, but I was initially using an older version of node (v0.8.20) and kept getting errors.
It might be good to specify the node version on packages.json.
problem.txt specifies that the app should be run on 'localhost:3000', but later specifies that the port number will be provided by expressworks.
I have been recently working on the learnyounode & stream-adventure workshops so I assumed that the default of preferring process.argv[2] was still applying to this track.
Either the problem specification should clarify that port 3000 will be used, or the test should be updated to use a random port number which is supplied to the script.
$ expressworks verify 8-jsonme.js
Verifying "JSON ME"...
ACTUAL: "[{\"title\":\"Express.js Guide\",\"tags\":[\"node.js\",\"express.js\"],\"url\":\"http://expressjsguide.com\"},{\"title\":\"Rapid Prototyping with JS\",\"tags\":[\"backbone.js\",\"node.js\",\"mongodb\"],\"url\":\"http://rpjs.co\"},{\"title\":\"JavaScript: The Good Parts\",\"tags\":[\"javascript\"]}]"
EXPECTED: "Cannot GET /books"
# FAIL
Your solution to JSON ME didn't match the expected output.
Try again!
The official solution:
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
app.use(bodyParser.urlencoded({extended: false}))
app.post('/form', function(req, res) {
res.send(req.body.str.split('').reverse().join(''))
})
app.listen(process.argv[2])
gives: Error: Cannot find module 'body-parser'
But this works:
var express = require('express');
var app = express();
app.use(express.urlencoded({extended: false}));
app.post('/form', function(req, res) {
res.end(req.body.str.split('').reverse().join(''));
});
app.listen(process.argv[2]);
My answer below is almost identical to the official answer and produces the same output, which is not "correct" in that it spans multiple lines and the correct output is all one line. I don't see anything wrong with my code.
var fs = require('fs');
var express = require('express');
var app = express();
app.get('/books', function(request, response) {
fs.readFile(process.argv[3], function(error, data) {
if (error) {
console.log(error);
}
response.json(JSON.parse(data));
});
});
app.listen(process.argv[2]);
My Code :
var express = require('express')
var bodyparser = require('body-parser')
var app = express()
app.use(bodyparser.urlencoded({extended:false}))
app.post('/form',function(req,res){
req.body.str.split('').reverse().join('')
})
app.listen(process.argv[2]);
Its not running in the terminal
Its hanging up
[Express.js newbie!]
After having a hard time with error messages from Connect in the Form Posting exercise, I Googled the issue I was facing and came across this Stack Overflow question:
http://stackoverflow.com/questions/22209388/node-express-module-throwing-no-method-errors
The responder suggests the use of body-parser, as does the list of supported middleware on the Express.js website.
Am I mixing things up, or is the exercise outdated?
My solution, for reference:
var port = process.argv[2]
var express = require('express'),
bodyParser = require('body-parser')
var app = express()
app.use(bodyParser.urlencoded())
app.post('/form', function(req, res) {
res.end(
req.body.str.split('').reverse().join('')
)
})
app.listen(port)
ExpressWorks currently uses Workshopper v0.33 which colours code snippets with pygmentize. It passes the parameter terminal256
to pygmentize - but Windows terminals don't support 256 colours (as you saw they interpret these colours very differently!).
v0.4+ of Workshopper doesn't have this problem (it uses msee instead of pygmentize).
Upgrade to v0.7.2, which is the newest version before v1. This didn't break anything when I tested it (briefly).
Hi,
I copied the answer from the solution then also its not working..
can you guys tell me why iuts not working
C:\Users\Desktop\node-school\express> expressworks run hello-world.js
Running "HELLO WORLD!"...
module.js:340
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (C:\Users\Desktop\node-school\express\hello-world.js:1:77)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect as oncomplete
I have had two people running on two separate machines with weird Expects
results.
From what I can tell it is due to some of the processes not being killed after the exercises have been completed. Because most of the exercises all run on the same port number, we are actually verifying to an old service.
running
$ ps aux | grep node
on these machines showed around 5 / 6 processes all belonging to the express works workshop.
Users need to run killall node
before verifying some exercises. See:
$ expressworks verify jade.js
Verifying "JADE"...
ACTUAL EXPECTED
------ --------
"<h1>Hello World</h1><p>Today is Wed Dec 11 2013.</p>" != "Hello World!"
# FAIL
Your solution to JADE didn't match the expected output.
Try again!
thanks for putting these lessons together!
express was not installed by default and hence, solution didn't worked. Since, I already had some knowledge regarding node, it was easy to find, but for absolute beginners it's hard to figure out what's going wrong. Please add all required modules to complete the challenges as dependency of the package.
I am finding the ExpressWorks instructions incomprehensible. Perhaps I am missing some prerequisites. I’ve written out my questions below to show the level of ignorance I am coming to this learning session with. If you have suggestions about where to go to learn what I need before I start, please let me know.
For example, Exercise 2 of 8 (static) says:
Please don't use ANY routes like app.get. ONLY static.
I wonder:
Your solution must listen on the port number supplied by process.argv[2].
I wonder:
4. What listens?
5. Is this like the Hello World one where I used this:
var app = express();
...
app.listen(process.argv[2]);
This is how you can call static middleware:
I wonder:
6. What is static middleware?
7. Where can I learn about it?
For this exercise expressworks will pass you the path:
app.use(express.static(process.argv[3] || path.join(__dirname, 'public')))
I wonder:
8. Is app var app = express();?
9. If so, what is express?
10. Where did the path variable come from?
This what I think is supposed to happen: process.argv[3] points to an HTML file. I am supposed get this HTML file and send it back in a response. I’m supposed to wait for a request from process.argv[2], but I don’t know if I’m supposed to parse that request in any way.
I'm using GitBash in windows 8. I've earlier used planetproto & learnyounode and things works perfect. This one just hangs after selecting any challenge.
Have the same issue with stevekane/promise-it-wont-hurt#31 although other nodeschool.io electives works fine.
using res.send(obj)
gives an error
ACTUAL EXPECTED
────────────────────────────────────────────────────────────────────────────────
"{" != "{\"results\":\"recent\",\"type\":\"quote\",\"page\":\"8\"}"
" \"results\": \"recent\"," !=
" \"type\": \"quote\"," !=
" \"page\": \"8\"" !=
"}" !=
────────────────────────────────────────────────────────────────────────────────
using res.end(JSON.stringify(obj))
works
i have post the official solution but verify got wrong
$ expressworks verify expressword.js
Verifying "STYLISH CSS"...
ACTUAL EXPECTED
------ --------
"Error: EACCES, open '/usr/local/lib/node_modules/expressworks/problems/stylish_css/public/main.css'" "Error: EACCES, open '/usr/local/lib/node_modules/expressworks/problems/stylish_css/public/main.css'"
"" != null
# FAIL
Your solution to STYLISH CSS didn't match the expected output.
Try again!
the official solution
var app = express()
app.use(require('stylus').middleware(process.argv[3]));
app.use(express.static(process.argv[3]));
app.listen(process.argv[2])
var express = require('express')
var app = express()
app.get('/', function(req, res) {
res.write('Hello World!')
res.end()
})
app.listen(process.argv[2])
And when I run:
expressworks verify myprog.js
it fails with the following message
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
*. Ran the same program with a hardcoded 3000 port and invoking localhost:3000 worked from the browser and showed the "Hello World!".
Hi there!
When I run expressworks in the terminal and execute a problem I get this error:
module.js:338
throw err;
^
Error: Cannot find module 'workshopper-exercise'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/usr/local/lib/node_modules/expressworks/exercises/hello_world/exercise.js:3:21)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
I'm using OSX 10.6.8
banquisalm:express banquisalm$ node --version && express --version && expressworks --version
v0.12.0
4.11.2
[email protected]
Cheers ;)
Trying to run the Hello World exercise on Linux:
eric@nas:~/expressworks$ expressworks run program.js
Running "HELLO WORLD!"...
module.js:340
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/eric/expressworks/program.js:1:77)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
My program.js looks like:
var express = require("express");
var app = express();
app.get("/", function(req, res) {
res.end("Hello World");
});
app.listen(process.argv[2]);
It'd be quite cool to show users how they can profit from app.param
.
app.param('message_id', function(req, res, next, messageId) {
req.computedHash = require('crypto')
.createHash('sha1')
.update(new Date().toDateString() + messageId)
.digest('hex')
next();
});
app.get('/:message_id', function(req, res, next) {
res.send(req.computedHash);
});
Maybe worth mentioning there are two ways to approach this problem? Showing the beginners not everything needs to be handled in a route handler might be a nice tip!
WDYT?
Continuously getting this error:
Error: EACCES, open '/usr/local/lib/node_modules/expressworks/problems/stylish_css/public/main.css'
my solution:
var express = require('express')
var app = express()
var stylus = require('stylus')
var STATIC_DIR = process.argv[3]
app.use(stylus.middleware(STATIC_DIR))
app.use(express.static(STATIC_DIR))
app.listen(process.argv[2])
You can see in the screenshot that both solutions are not being loaded :(
Here my code:
var express = require('express'),bodyparser = require('body-parser');
var app = express();
app.use(bodyparser.urlencoded({extended: false}));
app.post('/form',function(req,res){
req.body.str.split('').reverse().join('');
});
app.listen(process.argv[2]);
When I tried verify this code, I've got this:
events.js:85
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (_http_client.js:215:15)
at Socket.socketOnEnd (_http_client.js:300:23)
at Socket.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
When I try to test the last exercise i get this output:
ACTUAL: "Cannot GET /books/"
EXPECTED: "Cannot GET /books"
Am I missing something or is just the solution wrong?
This issue can be tested against this simple example:
var app = require('express')();
app.listen(process.argv[2]);
save it in file.js the check it with:
expressworks verify file.js
Trying out the Hello World exercise in Windows, and I get an error:
C:\Users\Eric>node -v
v0.10.25
C:\Users\Eric>expressworks run expressworks.js
C:\Users\Eric\expressworks.js(1, 1) Microsoft JScript runtime error: Object expected
Not sure why it's running JScript. Node runs fine, and expressworks shows the menu fine.
My code looks like this:
var express = require("express");
var app = express();
app.get("/", function(req, res) {
res.end("Hello World");
});
app.listen(process.argv[2]);
I ran the verification of my solution twice, once thru sudo and once without. Both times, my solution seemed to work, but the verification step failed.
❯ expressworks verify index.js
Verifying "PARAM PAM PAM"...
ACTUAL EXPECTED
------ --------
"663918365c1cf4aa90e1b997464837eeb216ff69" != "Cannot PUT /message/3f0a916de79d2a84e747342296f9ddb8"
# FAIL
Your solution to PARAM PAM PAM didn't match the expected output.
Try again!
❯ sudo expressworks verify index.js
Password:
Verifying "PARAM PAM PAM"...
ACTUAL EXPECTED
------ --------
"467e7714bb0b77755e016a3737d2b8d961a3bd45" != "Cannot PUT /message/fd42373de17b40c04517a6e4c956778d"
# FAIL
Your solution to PARAM PAM PAM didn't match the expected output.
Try again!
My code (slightly different than the provided solution, but the same in spirit):
"use strict";
var express = require("express");
var crypto = require("crypto");
var app = express();
var port = process.argv[2];
app.put("/message/:id", function(req, res) {
var id = req.params.id;
var date = crypto.createHash("sha1").update(new Date().toDateString() + id).digest("hex");
res.end(date);
});
app.listen(port);
I tried removing "use strict"
as well as changing res.end(date)
to res.send(date)
to see if either was causing the verification script to fail to execute, but neither step resolved anything.
OS X 10.9
node v0.10.21
I am trying to pass challenge 1, by need run verify twice, and after verified, the node web server both 3000 and 3001 should be killd, or it can't run challenge 2.
$ expressworks verify 01-hello_world.js
Verifying "HELLO WORLD!"...
ACTUAL EXPECTED
------ --------
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
Verifying "HELLO WORLD!"...
ACTUAL EXPECTED
------ --------
"Hello World!" "Hello World!"
# PASS
Your solution to HELLO WORLD! passed!
$ ps -awx | grep node
31914 ttys004 0:00.64 /usr/local/Cellar/node/0.10.21/bin/node 01-hello_world.js 3000
31915 ttys004 0:00.62 /usr/local/Cellar/node/0.10.21/bin/node /usr/local/share/npm/lib/node_modules/expressworks/problems/hello_world/solution.js 3001
I can't seem to verify my solution (or the Original Official solution posted as part of the project) for the 'Good Old Form' problem, it just hangs waiting for Actual and Expected results but never receives any.
Shouldn't the expected output be the file?
Verifying "STATIC"...
ACTUAL EXPECTED
------ --------
"<html>" != "Cannot GET /"
" <head>" != null
" <title>expressworks</title>" != null
" </head>" != null
" <body>" != null
" <p>I am red!</p>" != null
" </body>" != null
"</html>" != null
# FAIL
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!
I can't understand why this is not accepting my code, the output is the same. here is my program.js:
var express = require('express')
var app = express()
var fs = require('fs')
app.get('/books', function(req, res){
var filename = process.argv[3]
fs.readFile(filename, function(e, data) {
if (e) return res.send(500)
try {
books = JSON.parse(data)
} catch (e) {
res.send(500)
}
res.json(books)
})
})
app.listen(process.argv[2])
And this is what the response is to "expressworks verify program.js"
Your submission results compared to the expected:
ACTUAL EXPECTED
────────────────────────────────────────────── ──────────────────────────────────
"[" != "[{\"title\":\"Express.js Guide\",\"tags\": [\"node.js\",\"express.js\"],\"url\":\"http://expressjsguide.com\"},{\"title\":\"Rapid Prototyping with JS\",\"tags\":[\"backbone.js\",\"node.js\",\"mongodb\"],\"url\":\"http://rpjs.co\"},{\"title\":\"JavaScript: The Good Parts\",\"tags\":[\"javascript\"]}]"
" \"title\": \"Express.js Guide\"," !=
" \"tags\": [" !=
" \"node.js\"," !=
" \"express.js\"" !=
" ]," !=
" \"url\": \"http://expressjsguide.com\"" !=
" }," !=
" {" !=
" \"title\": \"Rapid Prototyping with JS\"," !=
" \"tags\": [" !=
" \"backbone.js\"," !=
" \"node.js\"," !=
" \"mongodb\"" !=
" ]," !=
" \"url\": \"http://rpjs.co\"" !=
" }," !=
" {" !=
" \"title\": \"JavaScript: The Good Parts\"," !=
" \"tags\": [" !=
" \"javascript\"" !=
" ]" !=
" }" !=
"]" !=
────────────────────────────────────────────────────────────────────────────────
✗ Submission results did not match expected!
# FAIL
Your solution to JSON ME didn't pass. Try again!
Please help!
The workshop is incompatible with the version 4 of Express.
The main problem is with the changes in middleware whose names have changed and are now unbundled from Express, this needing to be npm installed. This affects primarily good_old_form.
I've also add some errors during verify but couldn't attribute it with certainty to Express v4.
The sample code for Hello World! is incorrect. The app.get statement directs uses to write:
app.get('/', function(){...})
when the correct answer is
app.get('/home', function(){...});
I'm getting this error when trying to run or verify my solution. I've also tried the solution in the solution.js but it didn't work as well. I'm on Windows 7.
One thing it's worth mentioning is that I installed the "connect" module, since in the problem description, is said that "Express has urlencoded() middleware (from Connect library)". I'm not sure if I have to install it or if it is already a dependency of the Express module.
In the [email protected], the solution verification for the last 3 problems
» PARAM PAM PAM
» WHAT'S IN QUERY
» JSON ME
are broken and needs to be fixed. I am using node v0.10.26.
Hey I've got an 'express koans' thing I set up a while back: https://github.com/timoxley/express-koans
I'd thought to rejig them into workshopper, but I don't really use express anymore so meh.
Just thought I'd let you know you're welcome to steal any exercises from there if you think they're useful.
straight up wrong
expressworks verify program.js
Verifying "WHAT'S IN QUERY"...
ACTUAL: "{\"results\":\"recent\",\"type\":\"quote\",\"page\":\"7\"}"
EXPECTED: "Cannot GET /search/?results=recent&type=quote&page=7"
# FAIL
Your solution to WHAT'S IN QUERY didn't match the expected output.
Try again!
basically you can pass this problem by omitting the route. If you use the provided solution (or a correct solution as in my case) you do not pass this problem. I would fix it myself but I'm unfamiliar with the way the expected solution is generated in https://github.com/azat-co/expressworks/blob/master/problems/whats_in_query/setup.js
Also found problem 8 does something similar. I tried npm install express in these directories just in case that was the issue but it is not. Let me know if you have trouble reproducing the bug.
the expected output is not right it seems. it is expecting "Hello World!"--which the solution for question 1.
Verifying "GOOD OLD FORM"...
ACTUAL EXPECTED
"Express.js rocks!" != "Cannot POST /form"
when change app.post to app.get, the solution passed but it should not be the case
Wow. This is pathetic. I can’t get past the first exercise. Can anybody tell me what I’m doing wrong?
Some info. I am working on a Mac. Below are the commands that I type in the terminal and info on the output. After that is my code.
$ sudo npm install express --save
[entered password, much output, nothing in red...I think it went okay]
$ killall node
No matching processes belonging to you were found
$ expressworks run Express.js
35557
Cannot GET /home
Here’s my code
Express.js:
var express = require('express');
var app = express();
console.log(process.argv[2]);
app.get('/', function(req, res) {
res.end('Hello World!');
})
app.listen(process.argv[2]);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.