I'm new to node.js; I am reading a book and following it word for word. I have recently run into a problem and I do not know how to solve it. The book asks me to create a client app, I have the code which matches the book's exactly but doesn't run. Below is the code:
fiboclient.js:
var http = require('http');
var util = require('util');
[
"/fibonacci/30", "/fibonacci/20", "/fibonacci/10",
"/fibonacci/9", "/fibonacci/8", "/fibonacci/7",
"/fibonacci/6", "/fibonacci/5", "/fibonacci/4",
"/fibonacci/3", "/fibonacci/2", "/fibonacci/1"
].forEach(path => {
util.log('requesting ' + path);
var req = http.request({
host: "localhost",
port: 3002,
path: path,
method: 'GET'
}, res => {
res.on('data', chunk => {
util.log('BODY: ' + chunk);
});
});
req.end();
});
package.json:
{
"name": "fibonacci",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "DEBUG=fibonacci:* node ./bin/www",
"server": "SERVERPORT=3002 node ./fiboserver",
"client": "node ./fiboclient"
},
"dependencies": {
"body-parser": "~1.17.1",
"cookie-parser": "~1.4.3",
"debug": "~2.6.3",
"ejs": "~2.5.6",
"express": "~4.15.2",
"morgan": "~1.8.1",
"serve-favicon": "~2.4.2"
}
}
output:
> fibonacci@0.0.0 client
/home/zschiff/Dropbox/Personal/Node/ch04/fibonacci
> node ./fiboclient
29 May 11:37:56 - requesting /fibonacci/30
29 May 11:37:56 - requesting /fibonacci/20
29 May 11:37:56 - requesting /fibonacci/10
29 May 11:37:56 - requesting /fibonacci/9
29 May 11:37:56 - requesting /fibonacci/8
29 May 11:37:56 - requesting /fibonacci/7
29 May 11:37:56 - requesting /fibonacci/6
29 May 11:37:56 - requesting /fibonacci/5
29 May 11:37:56 - requesting /fibonacci/4
29 May 11:37:56 - requesting /fibonacci/3
29 May 11:37:56 - requesting /fibonacci/2
29 May 11:37:56 - requesting /fibonacci/1
events.js:163
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:3002
at Object.exports._errnoException (util.js:1050:11)
at exports._exceptionWithHostPort (util.js:1073:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
npm ERR! Linux 4.4.0-78-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "client"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! fibonacci@0.0.0 client: `node ./fiboclient`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fibonacci@0.0.0 client script 'node
./fiboclient'.
npm ERR! Make sure you have the latest version of node.js and npm
installed.
npm ERR! If you do, this is most likely a problem with the fibonacci
package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./fiboclient
npm ERR! You can get information on how to open an issue for this
project with:
npm ERR! npm bugs fibonacci
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls fibonacci
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/zschiff/Dropbox/Personal/Node/ch04/fibonacci/npm-
debug.log
any help is appreciated.
via Zachary Schiff
No comments:
Post a Comment