Jump to content

Node.js multiple responsive pages?

Smiffy_

Hey,

 

I'm trying to use Node.js alongside express and socket to load two pages, one for settings/preferences and the other to display information/data that is responsive to the inputs from the first settings/preferences page.

I have done some previous work with Node.js but for the life of me I can't seem to find a way to do this (usually I do everything through one page). I'm guessing this is because I'm approaching it incorrectly and would love for someone to inform how I should approach this properly.

 

Any help would be greatly appreciated,

Ryth

Link to comment
Share on other sites

Link to post
Share on other sites

Hi, I don't think I understand. Do you mean have like website/settings and website/info hosted from one script?

Computers r fun

Link to comment
Share on other sites

Link to post
Share on other sites

On 9/10/2019 at 3:21 AM, TheNuzziNuzz said:

Hi, I don't think I understand. Do you mean have like website/settings and website/info hosted from one script?

So I wish to make a basic application in which I have an 'admin' page where I can manually adjust some data values. Alongisde another page which is shown to the user that updates live to the changes made from the 'admin' page.

Link to comment
Share on other sites

Link to post
Share on other sites

18 hours ago, Smiffy_ said:

So I wish to make a basic application in which I have an 'admin' page where I can manually adjust some data values. Alongisde another page which is shown to the user that updates live to the changes made from the 'admin' page.

use socket.io, connect to that from the front end then emit a message when a setting is changed.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, vorticalbox said:

use socket.io, connect to that from the front end then emit a message when a setting is changed.

My issue is with how to host two seperate pages, i.e. admin page on /admin and viewer page on /viewer using Node.js

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, Smiffy_ said:

My issue is with how to host two seperate pages, i.e. admin page on /admin and viewer page on /viewer using Node.js

I would advise using express. You can serve static html files from a directory with the following code:

 

const express = require('express')
const app = express()
const port = 3000

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

app.use('/static', express.static('public'))

 

Computers r fun

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, Smiffy_ said:

My issue is with how to host two seperate pages, i.e. admin page on /admin and viewer page on /viewer using Node.js

you should probably have your front end javascript request a new html and render it on a separate browser tab and then write a restful api in your server to serve it. Alternatively use html link which will open a new tab when user clicks on it. Next do what the above post suggest, use socket.io or whatnot to link them together so if you change settings in one, it will be reflected on the other.

 

Btw, are you exposing node.js server directly to the world wide web or are you running a proxy server in front of it?  

Sudo make me a sandwich 

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

×