Jump to content

a question about Nodejs

Guest
Go to solution Solved by Jisagi,

You could check out serve-index. It should mirror the default apache behaviour of listing directoy contents. There are also a few examples at the bottom of the README on their github page

a quick side note: im currently learning node js, i have no f*cking idea what im doing.

 

Ok so I want to make node JS act like Nginx or apache2. like I can drag in a index.html, node js willl see it and make it useable

 

Folder structure:

 

-docroot (this folder is for only indexs, no server junk, like /views/)

--index.html

---(folder)

---index.html

 

iif i add

 

-docroot

--index.html

---(folder2)

---index.html

 

Node JS will auto pick it up and use it.

 

My current server.js

var fs = require('fs');
var http = require('http');
var express = require('express');
var app = express();
var path = require('path');
let ejs = require('ejs');
const { JSDOM } = require( "jsdom" );
const { window } = new JSDOM( "" );
const $ = require( "jquery" )( window );
app.set("view engine", "ejs");
// ejs/jquery isnt working, so can ingore
app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname + '/index.html'));
});
app.get('/about', function(req, res) {
    res.sendFile(path.join(__dirname + '/about/index.html'));
});
app.use('/flyer/', express.static(path.join(__dirname, '/flyer/')))
app.use('/utils/', express.static(path.join(__dirname, '/utils/')))
app.get('*', function(req, res){
    res.status(404)
    res.sendFile(path.join(__dirname + '/utils/404.html'));
  });
//var data = fs.readFileSync('counter'); <-- ingore, not used
app.listen(8081);
console.log('Server running at http://127.0.0.1:8081/');

 

Link to comment
Share on other sites

Link to post
Share on other sites

You could check out serve-index. It should mirror the default apache behaviour of listing directoy contents. There are also a few examples at the bottom of the README on their github page

Gaming Rig: Ryzen 9 5950x | 2x16GB DDR4 3200MHz | XFX Reference 6800 XT | MSI Unify X570 | Corsair MP600 2TB, Samsung 850 Evo 500GB | bequiet 850W Straight Power 11

Server: Ryzen 5 3600 | 4x32GB DDR4 ECC 2400MHz | Asrock Rack X470D4U | Samsung EVO Plus 250GB, 6x Seagate Exos 8TB, Samsung 850 Pro 1TB | bequiet 550W Straight Power 11

Link to comment
Share on other sites

Link to post
Share on other sites

On 2/24/2021 at 3:11 PM, Jisagi said:

You could check out serve-index. It should mirror the default apache behaviour of listing directoy contents. There are also a few examples at the bottom of the README on their github page

Amazing. Just what i needed! you're more helpful than stackoverflow

Link to comment
Share on other sites

Link to post
Share on other sites

On 2/24/2021 at 3:11 PM, Jisagi said:

You could check out serve-index. It should mirror the default apache behaviour of listing directoy contents. There are also a few examples at the bottom of the README on their github page

I have a Quick question regarding this, How could i add More index type files? like index.ejs, index.htm, index.php (ya php blah blah)

 

Any way i could go about this?

 

Link to comment
Share on other sites

Link to post
Share on other sites

Not sure if it even lets you display an index.* file at all like an apache or nginx does. It does look like like it really is only good for listing directoy contents. I couldn't find anything regarding checks for something like and .htaccess like file for any possible configuration either. I might be wrong, but I don't think this allows for this kind of feature.

Gaming Rig: Ryzen 9 5950x | 2x16GB DDR4 3200MHz | XFX Reference 6800 XT | MSI Unify X570 | Corsair MP600 2TB, Samsung 850 Evo 500GB | bequiet 850W Straight Power 11

Server: Ryzen 5 3600 | 4x32GB DDR4 ECC 2400MHz | Asrock Rack X470D4U | Samsung EVO Plus 250GB, 6x Seagate Exos 8TB, Samsung 850 Pro 1TB | bequiet 550W Straight Power 11

Link to comment
Share on other sites

Link to post
Share on other sites

13 hours ago, Jisagi said:

Not sure if it even lets you display an index.* file at all like an apache or nginx does. It does look like like it really is only good for listing directoy contents. I couldn't find anything regarding checks for something like and .htaccess like file for any possible configuration either. I might be wrong, but I don't think this allows for this kind of feature.

I was looking on the Node_mod Folder, and i cant seem to find anything to refer to .html (only text/html) is there anything you can see i can mess with to get EJS working?

Link to comment
Share on other sites

Link to post
Share on other sites

I really don't 😕 Doesn't seem like this does what you need. 

Gaming Rig: Ryzen 9 5950x | 2x16GB DDR4 3200MHz | XFX Reference 6800 XT | MSI Unify X570 | Corsair MP600 2TB, Samsung 850 Evo 500GB | bequiet 850W Straight Power 11

Server: Ryzen 5 3600 | 4x32GB DDR4 ECC 2400MHz | Asrock Rack X470D4U | Samsung EVO Plus 250GB, 6x Seagate Exos 8TB, Samsung 850 Pro 1TB | bequiet 550W Straight Power 11

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×