After linking my css file to my html file and opening it using Express in Node.js, I encountered an issue where the css file did not load when running the webserver through Node.js. I assumed that since the css file was included in the html, it should work as expected. Can anyone help me troubleshoot this?
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body>
<h1>Reading in Value</h1>
<form action="/" method="post" >
<br/>
<label>Enter a UDP command in hex</label>
<br/><br/>
<input type="number" name="number" id="number">
<br/><br/>
<input type="submit" value="Submit" name="submit">
<meta name="viewport" content="width=device-width, initial-scale=1">
</form>
</body>
</html>
Node.js
// Sending UDP message to TFTP server
// Using dgram module to create UDP socket
var express = require('express');
var fs = require('fs');
var util = require('util');
var dgram = require('dgram');
var client = dgram.createSocket('udp4');
var bodyParser = require('body-parser');
var app = express();
var app2 = express();
// Parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// Parse application/json
app.use(bodyParser.json());
// Reading in the html file
app.get('/', function(req, res){
var html = fs.readFileSync('index2.html');
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(html);
});
// Sends user command via UDP
app.post('/', function(req, res){
// Define the host and port values
var HOST = '192.168.0.172';
var PORT = 69;
// Buffer with hex commands
var message = new Buffer(req.body.number, 'hex');
// Send packets to TFTP
client.send(message, 0, message.length, PORT, HOST, function (err, bytes) {
if (err) {
throw err;
}
res.send('UDP message sent to ' + HOST + ':' + PORT);
});
});
// Creates another port
app2.get('/', function(req, res){
client.on('message', function (message) {
res.send('Received a message: ' + message);
});
});
app.listen(3000, "192.168.0.136");
app2.listen(8000, "192.168.0.136");
console.log('Listening at 192.168.0.172:3000 and Receive message will be on 192.168.0.172:8000')