As I’m learning Node myself (so that I can use the bleeding-edge SAFE API’s), I thought I’d share my notes etc with anyone interested.
There was some talk here earlier about people getting into code, so I wanted to share what I learn about node as I learn it.
This first part is a real simple intro to Node and how to get your hands dirty with it. I will add more things when ready:
#What is NODEJS??
It takes JS (usually browser-only) and lets you use it on your PC!! As a real actual programming language like C#, Java etc!!
Now you can use JS like PHP / Ruby (which
sucked and were always fragmented), which lets you access anything (network traffic, DB’s, files, etc) that is on your PC! JS no longer restricted only to accessing web page stuff!! opens it to everything
Can now create whole web servers too! no more php, ruby, python etc! Completely contained and self-serving web apps! JS (frontend) devs can now do BACKEND TOO!!
A whole website / app / company can be JS + NodeJS instead of JS + Java etc!
Test if you have it: node/npm -v and to start using it: node (will give a shell)
Made up of lots of “modules” and “npm” node package manager gets more 4u!
MAKE A QUICK NODE.JS APP!!: Make a file called “node1.js” etc and type “console.log(‘helloWorld’)” and then command line: “node node1.js” and your node app should run and say “helloWorld”!!!
#GET & USE MODULES w/ npm
make 2 separate ___.js files, and make the first say: “var modTest = require(’./module2’);”.
Then make the second one (the one gettin imported) say “var a = ‘ModImportSuccessful!’;” and also “console.log(a);” and when you command line: “node ___(firstFile)___.js” it should print that success message!!
Using modules is EASY!! Also, GETTING modules is easy with NPM!! You can command line into ur folder and then just “npm install underscore” or anything you want, and it will get underscore for u, then “require(‘underscore’);” and “console.log(_);” and then when u run it, it will work and show u all the underscore commands avail!
#CREATE a NPM PACKAGE!!
If u make a node project, u gotta add all the packages u used so that ur project will work on ppl’s computers!! So u gotta make a package.
Command “npm init” to make one, ENTER ENTER ENTER…etc and open the new “package.json” it made u! It should have a “dependencies” part that has all the packages that u made / “npm install”'ed!! Awesome!! (if not, sometimes gotta reinstall with ‘npm install ____ -S’).
GREAT!! Now anyone can just get your whole node project from github, and do “npm install” and it will auto install all packages listed in the “package.json” and then work!!
Packages are what make Node so functional!! Lets u do sooo much crazy shiz with Node super easy!!
#RUN YOUR FIRST NODEJS SERVER!!!
Just run and go to localhost:3000 in your browser to see it working!!
Can replace “hi” response with images, html pages, etc!!
#EXPRESS.JS!! – coming real soon!