Dr. Greg M. Bernstein
April 11th, 2021
node_modules
to the Linux serverpackage.json
PM2
DrBsClasses.org
ssh student1@drbsclasses.org
)node_modules
directory. Recreate it with npm install
and package.json
studentN
where N is and integer127.0.0.1
and port 3000 + N
3001
const express = require('express');
const app = express();
const port = 3001; // Should be 3000 + N, where you are studentN
// I'm student1
let count = 0; // Visit count
let startDate = new Date(); // Server start Date time
app.get('/', function (req, res) {
count++;
res.send(`Hi from Dr. B., Visited: ${count} times.`);
});
app.get('/uptime', function(req, res){
let curDate = new Date();
res.send(`Current Date/Time: ${curDate.toLocaleString()}, Server Up Since: ${startDate.toLocaleString()}`);
})
host = '127.0.0.1';
app.listen(port, host, function () {
console.log(`deployTest.js app listening on IPv4: ${host}:${port}`);
});
node_modules
(only have to do this once)node serverName
(just like you do locally)ctl+C
to stop the serverhttps://www.drbsclasses.org/studentN/node
where N is an integer from your assigned account name./
is absolute but ./
is relative!pm2 start serverName.js
pm2 stop serverName.js