Login Register


Node.js Introduction - Environment Setup filter_list
Author
Message
Node.js Introduction - Environment Setup #1
[Image: stxPVW1.png]

--

INTRODUCTION
The following series of guides will be fragments of what shall be called the "Introduction to Node.js" by IO. Before we start hoping into basic conventions, we must first talk about what Node.js is, how it is used currently and where it is going.
Node.js is a runtime environment designed to develop server-side web applications. This is completely reliant on Google's invention of the V8 JavaScript engine that Chrome uses to compile down its JavaScript quickly using C++. That being said, Node.js is written in JavaScript. If you want more information on the V8 engine a good source would be https://developers.google.com/v8/intro?hl=en. Although Node.js applications are written in JavaScript, the majority of Node.js is pre-compiled C++ which provides an extra boost in the output of speed.

Similar to Ruby's gems, Node.js has a package manager named NPM "Node Package Manager". You can easily install any package that you've found by typing:
Code:
npm install package_name

--

PREREQUISITES
For you to properly follow this guide you will need too install Node.js!
You can easily do so here: http://nodejs.org

--

ENVIRONMENT SETUP
Now that you've made it this far, lets hop into setting up a Node.js environment.
Every Node.js application that you make will require the file "package.json". This file tells Node.js crucial information about your application such as the name, description, version, whether its a private module, dependencies, etc. You can quickly build this file by typing
Code:
npm init
in the directory that you wish to start building your application. However, it's better to know what it actually looks like and what it does.

> an example basic package.json
Code:
{     "name": "tutorial-app",     "version": "0.0.1",     "description": "this is a tutorial app",     "private": true,     "dependencies": {          "mysql": "*",          "dank-dependency": "0.3.4"     } }
Above you can see that the contents of the file is obviously JSON. The dependencies are all contained with their version number so that instantiating the application becomes as easy as
Code:
npm install
which will go through all the dependencies in your "package.json" and install them to a file in the directory named "node_modules".

NOTE: If your project is attached to a git repository, I highly suggest adding "node_modules" to your ".gitignore" as it becomes a bunch of space being used.
NOTE 2: To speed up your dependency installing, type
Code:
npm install package_name --save
"--save" will add the dependency to your "package.json" and take care of the versioning for you.

Lastly, you will create your main JavaScript file. This file is usually named "app.js" but you may name it whatever you want.
Once you have created this file, you may include your dependencies by writing code such as:
Code:
var mysql = require('mysql');

Now that you know how to create an environment for a Node.js application, I will start going into guides on how to create simple applications such as Client/Server & basic web applications. If you have any requests on tutorials, please don't be afraid to PM or post below.

Next guide: N/A - Client/Server with the Net module.

Reply

RE: Node.js Introduction - Environment Setup #2
Great tutorial. I've recently been experimenting with Node.js myself.

Reply







Users browsing this thread: