background preloader

An Absolute Beginner's Guide to Node.js

An Absolute Beginner's Guide to Node.js
There's no shortage of Node.js tutorials out there, but most of them cover specific use cases or topics that only apply when you've already got Node up and running. I see comments every once and awhile that sound something like, "I've downloaded Node, now what?" This tutorial answers that question and explains how to get started from the very beginning. What is Node.js? A lot of the confusion for newcomers to Node is misunderstanding exactly what it is. An important thing to realize is that Node is not a webserver. Installing Node Node.js is very easy to install. I've Installed Node, now what? Once installed you'll have access to a new command called "node". $ node > console.log('Hello World'); Hello World undefined In the above example I typed "console.log('Hello World')" into the shell and hit enter. The other way to run Node is by providing it a JavaScript file to execute. hello.js console.log('Hello World'); $ node hello.js Hello World Doing Something Useful - File I/O example_log.txt

Felix's Node.js Beginners Guide « Home / All Guides There is lots of information about node.js, but given the rapid pace at which it is developing, it can be difficult for beginners to find good, current information on how to get started. This guide aims to provide exactly that, whilst staying updated with the latest stable version of node.js. This guide has been updated to reflect the latest changes in node 0.4.x, the currently stable branch of node.js. Learning JavaScript This guide assumes that you are already familar with JavaScript. Hello World Tutorial This tutorial guides you through installing node.js, including the creation of a simple hello world http server. Installation First of all: You should run a *nix operating system in order to use node.js at this point. The most common way to install node.js is to directly compile it from the downloaded source code. You can get the latest source code from $ wget $ tar -xzf node-v0.4.4.tar.gz $ cd node-v0.4.4 $ . Express

Beginner’s Guide to Node.js (Server-side JavaScript) Node.js – in simple words – is server-side JavaScript. It has been getting a lot of buzz these days. If you’ve heard of it or you’re interested in learning and getting some hands on it – this post is for you. So what exactly is the need of using JavaScript in the server? To explain it further, we’ll be talking about the idea of what Node.js is along with some hosting provider suggestions and installation tips. Let’s consider a case: Consider a website in which you need to load content dynamically from another web server which is slow. In the first method even though the code is simple the execution pauses for a while at the point where the slow web server is accessed. What’s the difference in Node.js? Getting started with Node.js Node.js is JavaScript. That said, the main highlight of Node.js – it is event-based asynchronous functions. Node.js could still make use of its processing power when the server is waiting for any other operation. How Does JavaScript Run On A Server? The codes:

The Node Beginner Book » A comprehensive Node.js tutorial About Documentation | node.js It's important for Node.js to provide documentation to its users, but documentation means different things to different people. Here on you will find three types of documentation, reference documentation, getting started documentation, and tutorials. Our API reference documentation is meant to provide detailed version information about a given method or pattern in Node.js. From this documentation you should be able to identify what input a method has, the return value of that method, and what if any errors may be related to method. You should also be able to identify which methods are available for different versions of Node.js. The Getting Started materials are meant to ease you into some of the concepts found in Node. Tutorials are for slightly more advanced topics, documentation meant to guide the user through specific use cases for Node.js.

npm basic commands The most commonly used npm commands After setting up n node.js development environment, you need to know some basic commands of node package manager npm. The followings are the most commonly used ones. Install package globally. Global packages are usually for executable commands. $ npm install <package name> -g # example $ npm install express -g # now we can use express to generate a new app $ express new app Install package locally. $ cd /path/to/the/project $ npm install <package name> # example $ npm install express # now you can use `var express = require( 'express' );` in your app Uninstall global package. $ npm uninstall <package name> -g # example $ npm uninstall express -g Uninstall local package. $ cd /path/to/the/project $ npm uninstall <package name> # example $ npm uninstall express Search package. $ npm search <package name> # example $ npm search express List global packages. $ npm ls -g List global packages detail. $ npm ls -gl List local packages. $ cd /path/to/the/project $ npm ls

Node.js Express Tutorial for Beginners The Internet is built on millions of networks that interconnect with each other. Traditionally, you send a web request to a web server and the web server returns HTML and the JavaScript used for client-side coding. The JS sent with the web page’s HTML runs on your computer. Node.js is a revolutionary concept that lets you write server-client applications between your web users and your web server. Learn the Node.js Express library from the beginning Getting Started with Node.js Express Node.js is an extended library that builds off of the original Node.js project. You need a basic JSON file to describe your application settings. The JSON is pretty self-explanatory. Learn how to work with NoSQL database design with MongoDB Getting Started with Coding Your First Application To get started with a basic project, you first need two variables: one variable for the application and another for the “Express” libraries. var express = require('express'); var app = express(); Error Handling

node.js basics Learning the basics of javascript and node.js After setting up the node.js development environment and know some common uses of npm commands. It’s time to learn the basics of javascript and node.js. Examples and source Examples and source are available on github Execute javascript files Let’s write a simple javascript to print Hey you on terminal. $ cd ~/Desktop $ node hey.js # -> Hey you Use external files To write a more modular application, you must split your code into files and break them into modules. node.js follows CommonJS conventions. It’s easier to see how it works from examples. source.txt I am Ben. read.js | Read the source file and print to the terminal write.js | Split the write action to this file run.js | Flow control // to use methods from other files we simply use `require` with path name var reader = require( '. So what’s the differences between the following 3? var something = require( '. The first and second are basically the same. exports VS module.exports Using `module.exports`