I didn't understand the context fully,
I think you are generating the code at client side and you want to save it.
If you want to save it in client side (file save option from browser), use the following library
https://github.com/eligrey/FileSaver.js
if you want to save it at server side, post the data to the server from your javascript itself and write the contents to a file in the server.
lets use jquery to post data. assume your code is there in the variable 'code'
$.post("/savecode",
{
data: code
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
This will post the data to the uri 'savecode'
i think, you created a static html page with some javascript inside and serving it from /var/ww/html/ folder of a apache or https server. this won't work, you need to serve it from a web application. i am choosing python flask here which is pretty simple.
to receive the data and store in a server, assuming that your static page is home.html and is there in templates folder
from flask import Flask, render_template, request
from werkzeug import secure_filename
app = Flask(__name__)
# Sending the home page when browsing /home
@app.route('/home')
def home():
return render_template('home.html')
# Saving the code posted by the javascript app
@app.route('/savecode', methods=['POST'])
def savecode():
f = request.files['file']
f.save(secure_filename(f.filename))
return 'file saved successfully'
if __name__ == '__main__':
app.run()
for more info, look flask docs : http://flask.pocoo.org/
You can create the server program in any language/framework that you are comfortable with.