node. JS Building Server methods

Source: Internet
Author: User

Do the front-end know, the company's project in their own computer set up the environment is a very troublesome thing, this article is mainly to share with you node. JS Build Server method, hope to help everyone.

    1. First of all: General PC No company configuration performance is good,

    2. Second: The construction of the company project in their own computer involves a lot of cache environment, resource environment package, database and other restrictions, add up enough to do a day (except the environment that is familiar with the company construction)

As far as my own company is concerned, I, as a front-end engineer,
The front-end is currently based on the polymer--implementation of the recent problem is not aware of the page I wrote there is no problem, but to successfully start the project Tomcat can see, because these pages can not be opened directly, will package resource parsing error,

var PORT = 3000;//var http = require (' http '), var url=require (' url '), var fs=require (' FS '), Var mine=require ('./mine '). Types;//var path=require (' path '); var server = Http.createserver (function (request, response) {var pathname = Url.parse    (Request.url). Pathname;    var Realpath = Path.join ("WebApp", pathname);    Set your own file name here;    var ext = path.extname (Realpath); Ext = ext?    Ext.slice (1): ' Unknown '; Fs.exists (Realpath, function (exists) {if (!exists) {Response.writehead (404, {' Content            -type ': ' Text/plain '});            Response.Write ("This request URL" + pathname + "is not found on the this server.");        Response.End (); } else {fs.readfile (Realpath, "binary", function (err, file) {if (err) {RE                    Sponse.writehead ($, {' Content-type ': ' Text/plain '});                Response.End (ERR); } else {VAR contentType = Mine[ext] | |                    "Text/plain";                    Response.writehead ($, {' Content-type ': ContentType});                    Response.Write (File, "binary");                Response.End ();        }            }); }    });}); Server.listen (port); Console.log ("Server runing at Port:" + Port + ".");

Mine.js (introducing the corresponding file)

Exports.types = {  "css": "Text/css",  "gif": "Image/gif",  "html": "Text/html",  "ico": "Image/x-icon",  "JPEG": "Image/jpeg", "  jpg": "Image/jpeg",  "JS": "Text/javascript",  "JSON": "Application/json",  "PDF": "Application/pdf",  "png": "Image/png",  "svg": "Image/svg+xml",   "swf": "application/ X-shockwave-flash ",  " TIFF ":" Image/tiff ",  " TXT ":" Text/plain ",  " wav ":" Audio/x-wav ",     " WMA ":" Audio/x-ms-wma ",  " wmv ":" Video/x-ms-wmv ",  " xml ":" Text/xml "};

Above two JS new successful, open http.js, and then found in the path settings, to change my current webapp to your own name Project name

Friendship tips: (The premise is that with JS in the same directory.) If the test project is in another file, then the path may have to be set to the absolute path _ this I did not try)
Below is the file that corresponds to my directory, three arrows are required other without setting


3. The console starts the server test is successful
See:
Open the directory where the project is entered node Http.js
Then prompt the port to start successfully,
Then enter the address of the file you want to test directly. Like mine.
Http://localhost:3000/index.html

All of this deployment is complete!

Note here: Be sure to add your own file path after the port number to run successfully. Otherwise it will be an error because the http.js is relatively simple to write, not directly mapped
http://localhost:3000
If something goes wrong, then rewrite the startup service
That is: node. js
Of course, if you're interested, you can rewrite node. js to refine it

Finally said: These two JS are I in the blog and Baidu to see some Daniel write, but their written tutorial is not clear (I level not enough to keep up with their ideas),
So thanks again to these bloggers Daniel,
Then try:

Run the test file on Nginx,

Build NODEJS+MANGODB test Project Migrate Angularjs tree to polymer

Angular's tree is the predecessor of the front-end Daniel wrote, has not been very understanding, I did not go to Baidu to see other Daniel wrote Ng tree (perhaps a lot more powerful)

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.