Porting your Kissy program to server-side –nodejs-kissy Project Introduction

Source: Internet
Author: User
Tags add prepare require

If you do not know Nodejs, please refer to nodejs.org, in short:

Node.js is a server-side JavaScript runtime environment with features such as non-blocking (non-blocking) and event-driven (Event-driven), node.js with a V8 engine, and Node.js implements a similar Apache and A Nginx Web service that allows you to build JavaScript-based web apps.

You can learn about Nodejs by sharing a few of our previous days in the team.


Nodejs-kissy Project

Kissy Taobao developed a lightweight and flexible JS framework, now is 1.1.5 version, and widely used in Taobao, in the browser to bring us a more refreshing experience, today let us further, we launched the Nodejs-kissy project, your Kissy The program can be ported seamlessly to the server side ^_^

Starting from here, Nodejs-kissy.

Thanks to the lightweight design of Kissy, the core module can be fully decoupled, so a simple hack on the Kissy can run on the Nodejs. But before you start, you should be ready to have NPM installed on the server (Linux/freebsd/macos/cygwin), NPM is the Nodejs package Manager, similar to Yum and Apt-get, through him to install Nodejs package is very convenient.

Prepare NPM:

Curl http://npmjs.org/install.sh  SH

If your account does not have permissions, first prepare the directory permissions:

sudo chown-r $USER/usr/local

After the installation is successful, you can install the Nodejs package through the "NPM install package_name" command

Install Nodejs-kissy dependencies: The server side does not have a browser environment, to run JS needs to simulate the real browser environment, so kissy need to rely on some packages:

NPM Install jsdom
npm install htmlparser
npm install Express
npm Install Connect

Install Nodejs-kissy:

NPM Install Kissy

Run "Hello World":

New File Helloworld.js

var S = require ("Kissy"). Kissy;
S.ready (function (S) {
    S.log ("Hello world!");
});

Run:

Node Helloworld.js

A more convenient transplant?

You may be curious, the server side does not have the browser, why Kissy can so easily run on the server side? This is mainly because the Kissy module loading mechanism is out of the browser environment, that is to say, Kissy.use, Kissy.add, Kissy.app is not related to the environment, it only relates to the way you organize the code and style, in addition, thanks to the kissy-dom implementation of the original ecological, Kissy only call to Domjs (Domjs of the high-level API is designed for the YUI3), so DOM-related operations can still be seamlessly grafted to the service , the Kissy porting is too easy for the deep coupling of the YUI3 core module.

Strategic trade-offs

Kissy Core and coarse-grained widgets based on the "one for all" concept, enabling Kissy to execute programs with fewer "introduction files" rather than necessarily using combo (even if the performance of combo is not necessarily increased), This makes the logical strategy of require easier.

What you see is what you receive

Like YUI3, Kissy-loader can also easily introduce external scripts, whether the scripts are hosted on the server or HTTP requests, as long as the developers require fullpath, very low carbon, such as I can run:

var S = require ("Kissy"). Kissy;
S.add ({
    "menu": {
        fullpath: "Http://cdn/menu.js"
    }
}). Use ("Menu", function (S) {
    new S.menu ("#ID ");
});

In short, how do you use Kissy in the browser, you write on the server side, then, the main work of the Nodejs-kissy project is more testing and improve its robustness. Nodejs-kissy and Kissy are based on the MIT protocol, and you can participate in nodejs-kissy development by fork GitHub projects.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.