-4

i can hit the url like

localhost/foodbucket/app.js

and see everything.

I want to prevent this.

var config = require('./config/config.js');
var app = require('express')();
var http = require('http').Server(app);
var mysql = require('mysql');
var pool = require('./config/database.js')(config.MYPOOL,mysql);
var io = require('./lib/socket.js')(http,mysql,pool);
var notificationcron = require('./crons/notification.js') 
(io,pool,mysql,config.NotificationStatus);
const router = app.Router();
router.get('/', "Error 404");

http.listen(4849, function() {
 console.log('Listening on port ' + 4849);
});

Solution : Add an .htaccess file inside Node directory. Write "Deny from all" in .htaccess

Zain Ul Abideen
  • 41
  • 1
  • 1
  • 5
  • During debug? Just hit `ctrl-c` in the terminal/command line you run your code – vahdet Jan 18 '19 at 11:31
  • 2
    So don't put the source code you want to run with Node.js in a directory that your web server will make available over HTTP. – Quentin Jan 18 '19 at 11:31
  • No, in the browser – Zain Ul Abideen Jan 18 '19 at 11:32
  • show some code what u wrtie otherwise how the possibly could we help u ? – sayalok Jan 18 '19 at 11:32
  • @Quentin actually nodejs app is a sub-application. So i want it in the same directory. – Zain Ul Abideen Jan 18 '19 at 11:33
  • 1
    @ZainUlAbideen How exactly are you running the server? – Milan Velebit Jan 18 '19 at 11:34
  • 1
    @ZainUlAbideen — No, you don't. If you want to execute it from PHP as your other question suggests … then you can put a full directory path in the PHP program and keep the JS source code somewhere sane. – Quentin Jan 18 '19 at 11:36
  • @ZainUlAbideen I agree with Quentin; you do NOT want your nodeJS in the same directory; if you are calling node from PHP, your node script can reside (almost) anywhere in your server and therefore you want it out of the public folder (since you won't want your script to be downloadable by the public...). – LFLFM Jan 18 '19 at 11:41
  • are you using express? do you have app.static(...) in you server side code? share your code. – AZ_ Jan 18 '19 at 11:45
  • @Ariz look now i shared code – Zain Ul Abideen Jan 18 '19 at 12:00

3 Answers3

2

To avoid having your web server share the data on a URL: Don't put the file in a directory that your web server is configured to publish over HTTP in the first place.

Then, if you need to access that file from PHP (as your previous question says you want), use either a relative directory path (one which starts ../ to go up a directory) or an absolute path (like /var/secret_node_code/app.js) to access it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-1

Your app.js file in the server/www path. I suggest create on the C:// a folder and paste you project to in after that, open a CMD and navigate to your folder and start your program with node app.js.

Blaze
  • 84
  • 5
-1

You should start your nodeJS application in console. Just open a console (in windows run cmd, in linux start a terminal) and go to the path, where is your nodeJS application. Enter node app.js and press enter.

After that you can see the result in the browser in url "localhost"