I've coded an application using NodeJS, ejs, express, peer, and socket.io that I've tested locally and everything seems to be working perfectly. Here's a little bit of the code from my main server.js
file:
// initialize the express application
const express = require('express');
const app = express();
// initialize the server
const server = require('http').Server(app);
// initialize socket io for real-time communication with the server
const io = require('socket.io')(server);
// import the peer-to-peer configuration and create the peer server
const { ExpressPeerServer } = require('peer');
const peerServer = ExpressPeerServer(server, {
debug: true
});
// set the engine as an embedded javascript
app.set('view engine', 'ejs');
// set where the public files exist
app.use(express.static('public'));
// set the peer server url
app.use('/peerjs', peerServer);
// generate the front-end index file for the study
app.get('/', (req, res) => {
res.render('index');
});
So I've recently gained access to a bit of personal server space at work and just wanted to see if I could deploy the application there. I've installed npm, NodeJS, and all the dependencies I need on the Linux server side and have uploaded the code to the server as well, but to be honest, I'm not quite sure where to go from here?
When testing the application locally, I know I need to enable NodeJS with node server.js
and then access my index.ejs file by going to localhost:<portnumber>/
on my browser. But I have no clue what the server equivalent is of this? This might be a ridiculous question, but as someone who hasn't worked on the server side of things before, does anyone know how to access the application from the server using my browser or of any web resources that would be good for understanding what's going on here?
Your question isn't ridiculous. It sounds like you've tested thoroughly so far. You may just want to familiarize yourself with testing on Unix/Linux console environment.
A good way to start would be to run the application, then run
ps -la
To make sure the express.js server is running, by looking for your line 'node server.js' in the list.
Next if you want to try having your server, well, serve a request you can use curl. The curl application can request a page using specified port. Here is an example taken from: https://stackoverflow.com/a/35339246/1061018
curl example.com:1234
So you might try
curl http://127.0.0.1:1234
or
curl http://localhost:1234
It should output the requested page as text.
But I have no clue what the server equivalent is of this
There isn't one! The concept of a server is not clear-cut. No machine is really a server, rather, these are just roles we assign to them. Any machine could be a server or a client. Your development machine acts as a server when you run Node - you are serving a web application.
You can run and access your application the exact same way on the linux server you're using at work as you would at home. That being said, there are a few considerations when you'd like to run an application for production versus for development .
You'll likely want to:
There are a number of online services which handle all of these concerns, and are probably a better fit for someone who does not have much experience. Check out Heroku .
If you'd like to go ahead and use a private server, there are a few things you'll need to do:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.