Node.js server giving 404 (Not Found) error

Advertisements My code is const https = require(‘https’); const fs = require(‘fs’); const options = { key: fs.readFileSync(‘server.key’), cert: fs.readFileSync(‘server.cert’) }; let requestCount = 0; const server = https.createServer(options, (req, res) => { requestCount++; // Process the request here… console.log("req.url:",req.url); if (req.url === ‘/’) { res.end(‘Hello, world!’); } else { res.statusCode = 404; res.setHeader(‘Content-Type’, ‘text/plain’);… Read More Node.js server giving 404 (Not Found) error

Convert Node method to C#

Advertisements I found this code to decrypt information using an AES key and a HASH code, but it is written in Node and I need to convert it to C# code: result = (AESKEYBASE64:string,HMACKEYBASE64:string,encryptedValue:string):{error:boolean, info:string, value:string | null } => { try{ const IV_SIZE = 16; const aesKey = Buffer.from(AESKEYBASE64, ‘base64’); const hmacKey = Buffer.from(HMACKEYBASE64,… Read More Convert Node method to C#

What is the current options available for reload in Node JS?

Advertisements What are the current available options to reload the files in node js web application development – with or without restarting – i.e both Couple of links are out-dated now 1. https://stackoverflow.com/questions/2925940/how-can-i-edit-on-my-server-files-without- restarting-nodejs-when-i-want-to-see-t 2. https://github.com/petruisfan/node-supervisor 3. https://github.com/kriszyp/nodules Please advise Thanks >Solution : Nodemon npm install -g nodemon # or npm install –save-dev nodemon nodemon… Read More What is the current options available for reload in Node JS?

How can I put the results of all If statements in a single output?

Advertisements I made a dice roll command with different outcomes, each outcome depending of the dice result obtained. This was all done for twitch bot for fun Below the code used: if (message == ‘!roll’) { client.say(channel, `@${userstate.username} A goblin appears before you, ready to attack. Roll a d20.`); const num = rollDice(); client.say(channel, `You… Read More How can I put the results of all If statements in a single output?

im learning backend route its all ok for first time but when i go back for the second time the site cant be reach

Advertisements if I go to the home page then I go to the contact page I go back again to the home page it says the site can’t be reached var http = require("http"); http .createServer(function (req, res) { console.log(req.url); const url = req.url; if (url === "/") { res.writeHead(200, { "Content-Type": "text/html" }); res.write("<h1… Read More im learning backend route its all ok for first time but when i go back for the second time the site cant be reach

Does node.exe for Windows have an option to specify environment variables?

Advertisements The node project I need to run requires certain environment variables. It runs on Windows, and it works fine when I try: set MY_ENV=abc & node . Is there an option in node.exe itself that can be used instead of this? Because there are cases where I can’t use the & symbol. I’m wondering… Read More Does node.exe for Windows have an option to specify environment variables?

Cannot read properties of undefined (reading 'username')

Advertisements hello i got this problem . And i still not find out my issue. thanks you for helping me this is code of login.js var express = require(‘express’); var router = express.Router(); var db=require(‘../database’); /* GET users listing. */ router.get(‘/login’, function(req, res, next) { res.render(‘login’); }); router.post(‘/login’, function(req, res){ var username = req.body.username; var… Read More Cannot read properties of undefined (reading 'username')