Using KOA as a static file server (Windows)

Source: Internet
Author: User
Tags app service

Usually learn Vuejs, Angularjs and other JS language, in the request Ajax, must go to configure IIS, more trouble, with this file, a small modification, you can run a server: http://localhost:3000/

Startorstop.bat

1 @echo off&setlocalenabledelayedexpansion2 REM #######################################################3 REM★★★★★ Note ★★★★★4 REM1. Add the user variable Node_path, point to the Global module directory node_modules--for example: E:\Skills\NodeJS\Data\node_global\node_modules5 REM2. Add global modules Koa and koa-static6 REMNPM I-g KOA7 REMnpm i-g koa-static8 REM3. Add Global module NPM29 REMnpm i-g npm2Ten REM ####################################################### One  A REM###### can modify zone START - SetAppname=helloworld::App Name - SetAppscript=app.js::start the program, basically fixed unchanged the Setappserverport=3000::KOA Service port, note consistent with the ports defined in App.js - REM###### can modify area END -  -  + : Main - Echo1. (default) Start service http://localhost:%appserverport% + Echo2. Stop the current app service http://localhost:%appserverport%--has a residual process of PM2 node A Echo3.Stop all services-no residue process at Set/P option=Please select the Operation code: -  - if  notDefined optionGoto Start ::default jump to start - if%option%==1Goto Start - if%option%==2GotoDelete - if%option%==3GotoKill in  - GotoError::other options, skip to Error to  +  - REM1. (default) Start service the : Start *     Echo"Start browser ..." $     Start/HTTPlocalhost:%appserverport%Panax Notoginseng     Echo"Start KOA service ..." -Pm2Start%appscript%--name%appname% the  +  A REM2. Stop the current app service the :d elete + PM2 Delete%appname% -  $  $ REM3. Stop all services - : Kill - PM2 Kill the  - Wuyi REM4. Select the error prompt the : Error -     Echo############################################ Wu     Echo########### Select Error, please re-select ########### -     Echo############################################ About     GotoMain

App.js

1' Use strict ';2 varServe = require (' koa-static '));3 varKOA = require (' KOA '));4 varApp =KOA ();5 varPort = 3000;6 7 //App.use (koa.static (__dirname + '/public '));8App.use (Serve ('. ')));9 TenApp.listen (Port,function(){ OneConsole.log (' Koa started successfully http://localhost: ' + port + '; press Ctrl-c to terminate. ' ); A});

BAT and js file package download: Http://files.cnblogs.com/files/chenshao/KoaPm2StaticServer.rar

Using KOA as a static file server (Windows)

Related Article

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.