Node.js

Saturday, April 12, 2014

Navigate to nodejs.org and download and install node


Open command prompt, enter path to node install, type in node, in the node shell, write javascript and executed


View node followed by js file executes it in the console, node is an execution engine for javascript files


Type in this basic javascript code and reexecute it in the node context, node is a simple wrapper around the v8 engine to execute code


Download and install the node.js tools for visual studio


File new project, blank node.js console app


Type in this code, set a breakpoint, hit f5, view the debugging experience


From solution node open command prompt


Execute node app.js, view the output


In sublime add require instruction, to grab the js file and assign it to a variable


Create file, add exports instruction, exports is object returned by require, with a string


In app.js, reference property in variable and log output to console


Export more than one thing or complex objects


Log them all


View the output


Export a function


Execute the function, require builds and returns a function


Change the function to a constructor method, use this


Create new instance of the object, call property of the object


Create new folder and file in the project


Create this simple member, takes in a msg as a param and write it to the console


Require loads index.js file by default, example encapsulation, might be more files, multiple dependencies, the consumer only has to know about one


Npmjs.org contains all the modules that can be loaded into node


Install underscore with node package manager


In directory structure view underscore module under node_modules


Use require to get the module underscore by name, think of require how to introduce script tags onto web pages


Uninstall and install underscore with save flag, dependency is added in package.json


Install express and save it as a dependency


File new project, blank node.js web application


Make these modifications to the package.json file


Grab the http library using require


Create web server, provide callback function, log the request url


Listen in on port 3000


Run the project, open browser navigate to localhost:3000, view forward slash appears since requesting the root


Modify url and view path appear in the console, all incoming requests are coming into the callback function


Return a response and end the response


View the response rendered on the web page


Right click the npm node and select manage node modules


Search for and install express web framework


Right click the project node and open command prompt here


Default Success Warning Important Info Inverse
B S W I ? O