How to call my nodejs file in my website?

February 3, 2016 1.9k views
Node.js WordPress Linux Commands DigitalOcean Nginx Ubuntu

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'));


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 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!

1 Answer

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.

by Mitchell Anicas
Node.js is an open source Javascript runtime environment for easily building server-side and networking applications. The platform runs on Linux, OS X, FreeBSD, and Windows, and its applications are written in JavaScript. Node.js applications can be run at the command line but we will...
Have another answer? Share your knowledge.