Build a simple web server using OnceIO

Poster admin  Post time 1484911795990
Keywords OnceIO  Node.JS 

OnceDoc is a managment system with high perforance and independence for enterprise contents. Based on the OnceIO Web frame, it can achieve modular storage and dynamic routing for Web.The front-end, backstage and the database definition are all saved in the same extension package. Every package represents an application with specific function, which could be realized or removed simply through add/delete the folder acquired from the package decompression. Anyone could install the module within 5 seconds. With the module extension package, you can extend your OnceDoc into mailbox, procedure management, community share, assets management, shopping center, etc. If any custome-built extension is desired, please contact us.


First step. Install onceio through npm

Write the following setence in the command window:

npm install onceio

Second step. Create a file named websvr.js in the project folder

websvr.js code is as follows:

var onceio = require("../onceio/onceio")

var app = onceio({
  home: "./"
  , listDir: true
  , debug: true
  , sessionTimeout: 60 * 1000

app.get("/", function(req, res) {
  res.end('Hello, world')

At first the server module will be acquired through 'require()'. In this example, the onceio folder is in the parent directory of the websvr.js file, therefore '../' is used. When the websvr.js file is in the same directory with the onceio folder, use './' in the command.

Then, a simple application is created and four properties are set, including:

home designates the main directory where the server operates.

listDir designates the power whether the app is capable to check the files under the directory. The default value is usually false in the released items.

debug determines the messages shown in the cmd board. When the debug value is true, the debug mode starts, all activities of the server will be shown; otherwise only the error message will be printed.

sessionTimeout sets the overdue time of the session, the "60 * 1000" in the example represents 1 second.

Third step. Operate the server

Open cmd, use cd command to locate the project directory. Execute the node websvr.js command to operate the server. cmd effect

Open the localhost:8054 in the server to get the following result:

webserver effect

Till now, a simple OnceIO server is built.



Source Code:





Reply (0)
  • #
OnceIO Node.JS