This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pattern | |
//Usually, you call a callback as the last thing you do inside a function. | |
//You might consider it synonymous with return, only JavaScript does | |
//not halt function execution when it hits it. It can be easy to accidentally | |
//let execution continue after calling a callback, when you really expected it to end. | |
//In order to make this easy to spot, and make sure execution stops in the way you expect, | |
//I recommend returning the callback function call. | |
// wrong! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
What is "this"? | |
In all programming languages, there is this idea of current scope and current context. In JavaScript we have a lexical scope and a current "this" context. | |
In JavaScript all new scopes are created through "function" definitions. But contrary to other c-like languages, this is the only way to make a new scope. For loops don't do it, if blocks don't do it, plain curly braces assuredly don't do it. This simplicity is both a blessing and a curse. First let's have a couple of examples to explain creating scopes. | |
This is an example of global scope: | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebSockets vs. Server-Sent events/EventSource | |
--------------------------------------------- | |
Both WebSockets and Server-Sent Events are capable of pushing data to browsers. To me they seem to be competing technologies. | |
What is the difference between them? When would you choose one over the other? | |
Websockets and SSE (Server Sent Events) are both capable of pushing data to browsers, however they are not competing technologies. | |
Websockets connections can both send data to the browser and receive data from the browser. | |
A good example of an application that could use websockets is a chat application. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Use Git | |
Most people in the node community use git for all their version control needs. It is an extremely powerful and robust tool. If you don't already use it, you should. | |
Don't wait until your program is "ready" before using git on it! Run git init in the root of your project folder right away, and commit your changes as you make them. It is a good habit, and can help avoid a lot of painful mishaps. | |
If you wish to share your program with others, then github is also a tremendously useful resource that most nodejs developers use. | |
A package.json File | |
========================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In JDK 7, the most important classes for text files are: | |
Paths and Path - file locations/names, but not their content. | |
Files - operations on file content. | |
StandardCharsets and Charset (an older class), for encodings of text files. | |
the File.toPath method, which lets older code interact nicely with the newer java.nio API. | |
In addition, the following classes are also commonly used with text files, for both JDK 7 and earlier versions: | |
Scanner - allows reading files in a compact way | |
BufferedReader - readLine | |
BufferedWriter - write + newLine | |
When reading and writing text files: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var http = require("http"); | |
var https = require("https"); | |
/** | |
* The default port that node servers bind to. | |
*/ | |
var DEFAULT_PORT = 5000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Since you asked a similar question, let's take it step by step. | |
//It's a bit longer, but it may save you much more time than I have spent on writing this: | |
//Property is an OOP feature designed for clean separation of client code. | |
//For example, in some e-shop you might have objects like this: | |
function Product(name,price) { | |
this.name = name; | |
this.price = price; | |
this.discount = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A map of HTTP header names with irregular case. | |
* IrregularHeaderNames.js | |
*/ | |
module.exports = [ | |
'Content-ID', | |
'Content-MD5', | |
'DNT', | |
'ETag', | |
'P3P', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Do: | |
================ | |
1.name the directory something related to your project. For example, if your project is named "Twisted", | |
name the top-level directory for its source files Twisted. When you do releases, you should include a version number suffix: Twisted-2.5. | |
2.create a directory Twisted/bin and put your executables there, if you have any. | |
Don't give them a .py extension, even if they are Python source files. | |
Don't put any code in them except an import of and call to a main function defined somewhere else in your projects. | |
(Slight wrinkle: since on Windows, the interpreter is selected by the file extension, | |
your Windows users actually do want the .py extension. | |
So, when you package for Windows, you may want to add it. |
OlderNewer