This is the source code of https://www.nodebeginner.org.
manuelkiessling / nodebeginner.org Goto Github PK
View Code? Open in Web Editor NEWA comprehensive Node.js tutorial for beginners
Home Page: https://www.nodebeginner.org
License: Other
A comprehensive Node.js tutorial for beginners
Home Page: https://www.nodebeginner.org
License: Other
This is the source code of https://www.nodebeginner.org.
it's really a very nice work. thanks @manuelkiessling ~ really great
xuqiang([email protected])
In the section where server.js is turned into a node module, the following is introduced:
exports.start = start;
It would be nice if the exports object was introduced. It's not entirely clear what it does, other than "it just works."
You know, in the programming world, nouns used to act as multiple roles. Especially those has general meanings, such as server
, router
, etc.
For example, server
could indicate a physical server, a logical server, and an object which name happens to be the word 'server'. If you translate them all into Chinese, people may have trouble to distinguish them and to understand what you really mean to.
Here is an example at url http://www.nodebeginner.org/index-zh-cn.html#routing-to-real-request-handlers
I believe the word 服务器 and 路由 here would mean to be objects instead of a real physical HTTP server and a physical router. Because in the context I believe you would really mean to transfer the request to the code snippet in the server.js
and then to the code snippet in the router.js
.
If you just keep them as is in English, it would be much clearer to the readers.
这意味着我们得将请求处理程序从服务器传递到路由中,但
感觉上这么做更离谱了,我们得一路把这堆请求处理程序从
我们的主文件传递到服务器中,再将之从服务器传递到路由。
http://www.nodebeginner.org/index-zh-cn.html#whats-needed-to-route-requests
I'm a beginner and I find something wrong when I console.log(querystring(string)["foo"] );
That querystring is not a function
url.parse(string).query | url.parse(string).pathname | | | | | ------ ------------------- http://localhost:8888/start?foo=bar&hello=world --- ----- | | | | querystring(string)["foo"] | | querystring(string)["hello"]
From router beginning example:
index.js
var server = require("./server");
var router = require("./router");
server.start()
server.js
var http = require("http");
var url = require("url");
function start(route) {
function onRequest(request, response) {
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname + " recieved.");
route(pathname);
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.write("Hello, world!");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.");
}
exports.start = start;
router.js
function route(pathname) {
console.log("Abount to route a request for " + pathname);
}
exports.route = route;
Error output:
c:\Projects\Personal\Node\learning-gulp\server.js:10
route(pathname);
^
TypeError: undefined is not a function
at Server.onRequest (c:\Projects\Personal\Node\learning-gulp\server.js:10:9)
at Server.emit (events.js:110:17)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:491:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:111:23)
at Socket.socketOnData (_http_server.js:343:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
I keep getting this error with my own code as well as your version of the application which I downloaded from this repo. Also, when I upload the image it doesn't appear in the tmp/ directory, Any ideas on how to fix?
(node:14700) DeprecationWarning: Calling an asynchronous function without callback is deprecated.
(node:14700) DeprecationWarning: Calling an asynchronous function without callback is deprecated.
fs.js:90
throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
^
Error: ENOENT: no such file or directory, unlink 'D:\Documents\GitHub\projects\node.js-beginner-web-app\tmp\test.png'
http://localhost:8888/upload
returns this:
I'm using node 7.4.0 and the latest version of formidable.
nodebeginner.org/code/application/requestHandlers.js - Line 37 - files object - sub property "filepath"
on node -v v16.14.0
should update: fs.rename(files.upload.path to fs.rename(files.upload.filepath,
Website is not supporting any responsive design
On this page:
https://github.com/manuelkiessling/nodebeginner.org/blob/master/index-en.html
this bit:
"(...) you need to install Node.js. Instead of repeating the process here, I kindly ask you to visit the official installation instructions"
has a broken link to: https://github.com/joyent/node/wiki/Installation
Hi guys i find a minor detail in
var exec = require("child_process").exec;
function iniciar(response) {
console.log("Manipulador de petición 'iniciar' fue llamado.");
exec("ls -lah", function (error, stdout, stderr) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write(stdout);
response.end();
});
}
//The name of the function its wrong and throw an exception change subir instead
function upload(response) {
console.log("Manipulador de petición 'subir' fue llamado.");
response.writeHead(200, {"Content-Type": "text/html"});
response.write("Hola Subir");
response.end();
}
exports.iniciar = iniciar;
exports.subir = subir;
The latest zipped code doesn't work on windows for file renaming. So I resort to file copying instead.
Dig in for a while. Come up with one solution. See below.
In the upload request handler, use code below for file copying.
fs.createReadStream(files.upload.path).
pipe(fs.createWriteStream('/tmp/test.jpg').
on('close', function(){
response.writeHead(200, {"Content-Type": "text/html"});
response.write("received image:
");
response.write("");
response.end();
}));
Receive below error when compling with NodeJs version 0.10.35 (downloaded from http://nodejs.org/download/)
C:\A Work\Study\NodeJs\Code>node index.js
module.js:340
throw err;
^
Error: Cannot find module 'formidable'
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:\A Work\Study\NodeJs\Code\requestHandlers.js:3:18)
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 Module.require (module.js:364:17)
C:\A Work\Study\NodeJs\Code>
这句代码没有生效,是自己写的url模块,还是nodejs自带的?无法获取pathname
The link http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb
it's broken.
Line 920 in f8c7b21
Please remote the link or correct please 👍
fs.js:101
throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
^
Error: ENOENT: no such file or directory, unlink 'D:\tmp\test.png'
at Error (native)
why cause this ?
test
Hi - please forgive me if this isn't the best place to post this issue. I just happily paid for the eBook version of The Node Beginner Book - the beginning was excellent and I'm continuing to enjoy the book. I've switched to the PDF version, and I'm a bit dismayed to find that all of the quotation mark pairs are ”mangled”. (It's not incredibly obvious in this font, but all of the quotation marks are right double quotes, which looks painful in a serif font.
It looks like there are at least some apostrophe issues, too. (See page 31, where "we're" becomes "weâ€TMre".
These aren't huge issues and I don't regret buying the book, but it'd be lovely not to have these ugly typographic stains on an otherwise great product.
Hi there, thanks for the fantastic resource!
It'd be fantastic to read this book on tablets. I tried very briefly to fix the site view on my iPad, but I can't come up with an 'elegant' solution. Basically, because #book is 640px wide and the font is large, the book content is crammed within a thin vertical strip, making it hard to read.
I messed with #book width, setting it to 1000px, which improves things but it's a terrible hack. You could potentially use Javascript to test whether it's being displayed on an iPad, and set the width accordingly (still a hack).
Or perhaps use a JS lib that detects a mobile device and uses a completely different layout, more suited for tablets/mobile?
Anyway, thanks again!
sdfsdfsd
It seems its been a while you've not been here @manuelkiessling . Isn't it?
There are some easy-to-solve issues, some solved ones(like #65 ), even two test(!) issues and no one is responsible for them.
Will you continue to develop the project or we should fork it(I myself prefer to continue on the main branch/version)?
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.