-3

Hi am trying to create in browser code editor for free knowledge sharing for high school students from basic level. after long struggle with search i got this link. i just did some setup and changes as per guidance available in that link.

var express = require('express');
var path = require('path');
var app = express();
var bodyParser = require('body-parser');
//app.use(bodyParser.urlencoded());

app.use(bodyParser.urlencoded({
  extended: true
}));


//compileX
var compiler = require('compilex');
var option = {stats : true};
compiler.init(option);

app.get('/' , function (req , res ) {

	res.sendfile( __dirname + "/index.html");

});


//app.post('/compilecode' , function (req , res ) {
app.post('/' , function (req , res ) {

    
	var code = req.body.code;	
	var input = req.body.input;
    var inputRadio = req.body.inputRadio;
    var lang = req.body.lang;
    if((lang === "C") || (lang === "C++"))
    {        
        if(inputRadio === "true")
        {    
        	var envData = { OS : "windows" , cmd : "g++"};	   	
        	compiler.compileCPPWithInput(envData , code ,input , function (data) {
        		if(data.error)
        		{
        			res.send(data.error);    		
        		}
        		else
        		{
        			res.send(data.output);
        		}
        	});
	   }
	   else
	   {
	   	
	   	var envData = { OS : "windows" , cmd : "g++"};	   
        	compiler.compileCPP(envData , code , function (data) {
        	if(data.error)
        	{
        		res.send(data.error);
        	}    	
        	else
        	{
        		res.send(data.output);
        	}
    
            });
	   }
    }
    if(lang === "Java")
    {
        if(inputRadio === "true")
        {
            var envData = { OS : "windows" };     
            console.log(code);
            compiler.compileJavaWithInput( envData , code , function(data){
                res.send(data);
            });
        }
        else
        {
            var envData = { OS : "windows" };     
            console.log(code);
            compiler.compileJavaWithInput( envData , code , input ,  function(data){
                res.send(data);
            });

        }

    }
    if( lang === "Python")
    {
        if(inputRadio === "true")
        {
            var envData = { OS : "windows"};
            compiler.compilePythonWithInput(envData , code , input , function(data){
                res.send(data);
            });            
        }
        else
        {
            var envData = { OS : "windows"};
            compiler.compilePython(envData , code , function(data){
                res.send(data);
            });
        }
    }
    if( lang === "CS")
    {
        if(inputRadio === "true")
        {
            var envData = { OS : "windows"};
            compiler.compileCSWithInput(envData , code , input , function(data){
                res.send(data);
            });            
        }
        else
        {
            var envData = { OS : "windows"};
            compiler.compileCS(envData , code , function(data){
                res.send(data);
            });
        }

    }
    if( lang === "VB")
    {
        if(inputRadio === "true")
        {
            var envData = { OS : "windows"};
            compiler.compileVBWithInput(envData , code , input , function(data){
                res.send(data);
            });            
        }
        else
        {
            var envData = { OS : "windows"};
            compiler.compileVB(envData , code , function(data){
                res.send(data);
            });
        }

    }

});

app.get('/fullStat' , function(req , res ){
    compiler.fullStat(function(data){
        res.send(data);
    });
});

app.listen(8080);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html>
<head>
	<title>Compilex</title>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/PreloadJS/0.6.0/preloadjs.min.js"></script>
</head>
<body>
<center>

<form id="myform" name="myform" method="post" action="/">
<h3>Your Code</h3>
<textarea rows="13" cols="100" id="code" name="code" ></textarea> 
<br/>
<div>
	<input type="submit" value="submit"  name="submit" />
</div>
<div>
	<br/>
Language : <select name="lang">
  <option value="C">C</option>
  <option value="C++">C++</option>
  <option value="Java">Java</option>  
  <option value="Python">Python</option> 
  <option value="CS">C#</option>  
  <option value="VB">VB</option>  
</select>
Compile With Input : 
<input type="radio" name="inputRadio" id="inputRadio" value="true"/>yes
<input type="radio" name="inputRadio" id="inputRadio" value="false"/>No
</div>
<h3>Output</h3>
<textarea rows="10" cols="100" id="input" name="input" ></textarea> 

<br />

</form>
</center>
</body>
</html>

Requirement: 1. how to compile the input for Python (how to configure with this app) 2. how to show the output in second textarea.

(note: spend lots of time with codemirror, ace editor examples and demo but couldn't use it efficiently as am new to this platform)

helps much appreciated

Thank you

2

Actually, you have just plain HTML and there is nothing in there that uses angular.

Adding a script tag alone does not make something "angular code". BTW, the tag is indeed in the wrong place, and it holds an ancient angular version. By now you should be using version 1.5.8. If you want to learn how to use angulular you should visit the tutorial and read through the docs and style-guide.

If you want to start now with angular its probably a better idea to dirtectly look at angular 2

|improve this answer|||||
0

Move <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> into the <head>. Not certain that this is your problem, but that'd be the first step in my book in the debugging process.

|improve this answer|||||
  • thanks for your response. just changed as you said. am facing with fallowing issue when try to run by "node server.js". – beep Sep 9 '16 at 7:40
  • F:\node examples\compilex-Demo1>node server.js Statistics for compilex is On express deprecated res.sendfile: Use res.sendFile instead server.js:19:6 *** function (arg0, arg1, arg2) { "use strict" log.call(deprecate, message, site) return fn.apply(this, arguments) } INFO: 8e0t16l.py created INFO: 8e0t16l.py successfully executed ! _____data { output: 'test\r\n[0x7FFE7C2830A0] ANOMALY: use of REX.w is meaningless (default operand size is 64)\r\n[0x7FFE7C333DC0] ANOMALY: uof REX.w is meaningless (default operand size is 64)\r\n' } – beep Sep 9 '16 at 7:42
  • Would you mind posting your server.js file? But it seems that all you really need to do is capitalize the 'f' in 'sendfile'. So basically change this: res.sendfile(__dirname + '/example.html'); to this: res.sendFile(__dirname + '/example.html'); The difference lies in the method name. I'd suggest getting a linter or looking into webstorm if you have the money to spend. It helps catch small bugs here and there – Miguel Solano Sep 10 '16 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.