By etisspb
I do have a node.js file with this code:
var express = require('express');
var app = express();
var path = require('path');
var Chance = require('chance');
var chance = new Chance();
app.get('/get-javascript-file', function(req, res) {
if (chance.integer({min: 1, max: 10}) == 1) {
res.sendFile(path.join(__dirname + '/someFile.js'));
} else {
res.sendFile(path.join(__dirname + '/someOtherFile.js'));
}
});
app.listen(80);
The nodejs basically based on the number the random function prints,sends as response the someFile.js or someOtherFile.js
Now, i do have a website called site.com hosted in let’s say Godaddy which calls this node.js each time someone accesses the website. How do i do that?! Any idea please? Thank you!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Most standard shared hosting does not support node applications. In order to run a node.js app the node runtime is required. The .js file cannot just be hosted on a standard LAMP server. This guide will walk you through setting up a node app.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.