javascript - Call function in nodejs from angular application -


i'm having angular app(angular-seed app) should call function in nodejs(web-server.js). function in nodejs calls batch file.

the op didn't mention express i'll provide alternative server side (node.js part) without using additional frameworks (which require installing via npm). solution uses node core:

web-server.js:

'use strict';  var http = require('http') var spawn = require('child_process').spawn var url = require('url')  function onrequest(request, response) {   console.log('received request')   var path = url.parse(request.url).pathname   console.log('requested path: ' + path)   if (path === '/performbatch') {     // call existing function here or start batch file this:     response.statuscode = 200     response.write('starting batch file...\n')     spawn('whatever.bat')     response.write('batch file started.')   } else {     response.statuscode = 400     response.write('could not process request, sorry.')   }   response.end() }  http.createserver(onrequest).listen(8888) 

assuming on windows, @ first use batch file test it:

whatever.bat:

rem append timestamp out.txt time /t >> out.txt 

for client side, there nothing add spoike's solution.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -