Click here to Skip to main content
14,486,801 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a web server but I wanted to add something to my site. I found a basic template I liked that was a .js file. .html and .php files work on my site.

All that shows up when I go to the index.js file is the code within the file.

My Link XX.XX.X.XXX/index.js
Top first couple lines that display:
const cron = require("node-cron");
const express = require("express");
const fs = require("fs");

What I have tried:

I tried installing Node and NodeJS which was successful as it shows the version but nothing changed on the front end.
root@tsl_system:~# nodejs -v
root@tsl_system:~# node -v

I have looked at a few other resources but they all seem like the same steps I have previously done and I dont want to keep installing items that are truly not needed.
Updated 23-Mar-20 1:27am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

If you navigate to a js file then, yes, you'll see the content as it is treated as a static file. You can't execute js in a browser by navigating to the file. If you want to execute the js you need to include the js file in an html\php\whatever file that the browser will process. So if you are using php then have a php file that returns html that includes your js file via a <script> tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month