background preloader

How do I get started with Node.js

How do I get started with 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

node.js beginner tutorials The Node Beginner Book ยป A comprehensive Node.js tutorial How To Node - NodeJS Best practices of building a website using node.js nodeapps/http-server node.js - Loading basic HTML in NodeJS Getting started with node.js A simple, standardised way of providing Javascript libraries. Define methods to make available to the world using exports. Import modules using require. In a previous slide I mentionded that node.js is easily extensible because it makes use of CommonJS. So what's that? CommonJS is an attempt to expand the standard library provided by the Javascript specification into something that is useful beyond the browser-based world that Javascript is normally confined to. This code example shows how CommonJS can be used. require is a construct used to import Javascript modules. There are other built-in modules for handling things like file I/O (the POSIX module), HTTP servers (there's a server and a client implementation in the HTTP module), generic TCP servers (the TCP module), DNS lookups (the DNS module) and several others. To write your own you define properties on the exports object which are then returned from a require() on that file.

Related: