
i have take a node js file below
app.js
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const fs = require("fs");
var createError = require("http-errors");
const passport = require("passport");
var path = require("path");
const session = require("express-session");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
var express = require('express');
var exphbs = require('express-handlebars');
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(express.static("./public"));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
var userLogin = {};
app.post("/api/login", (req, res) => {
fs.readFile("./data.json", (err, data) => {
var arr = [];
if (err) {
console.log(err);
} else {
if (data.toString()) {
arr = JSON.parse(data.toString());
}
var s = arr.find((item) => {
if (item.name == req.body.name) {
return item;
}
});
if (s) {
if (s.password == req.body.password) {
userLogin = req.body;
res.json({
status: "y",
meg: "login success",
data: s.name,
});
} else {
res.json({
status: "err",
meg: "wrong password ",
});
}
} else {
res.json({
status: "n",
meg: "no such user ",
});
}
}
});
});
app.get("/index", (req, res) => {
if (userLogin.name) res.render("index", { username: userLogin.name });
else res.render("login");
});
app.get("/", (req, res) => {
res.render("login");
});
var PORT = 3000;
app.listen(3000, function () {
console.log(`Listening on port ${PORT}`);
});
-------------------------------------
if i add "var express = require('express');"
it hsows error "
node app.js
V:\ga2\moban4943\k1\app.js:11
var express = require('express');
^
SyntaxError: Identifier 'express' has already been declared
?[90m at wrapSafe (internal/modules/cjs/loader.js:1001:16)?[39m
?[90m at Module._compile (internal/modules/cjs/loader.js:1049:27)?[39m
?[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:1
0)?[39m
?[90m at Module.load (internal/modules/cjs/loader.js:950:32)?[39m
?[90m at Function.Module._load (internal/modules/cjs/loader.js:790:14)?[39m
?[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_ma
in.js:76:12)?[39m
?[90m at internal/main/run_main_module.js:17:47?[39m
if i delete the code "var express = require('express');"
then it shows "Error: Cannot find module 'hbs' Require stack: - V:\ga2\moban4943\k1\node_modules\express\lib\view.js - V:\ga2\moban4943\k1\node_modules\express\lib\application.js - V:\ga2\moban4943\k1\node_modules\express\lib\express.js - V:\ga2\moban4943\k1\node_modules\express\index.js - V:\ga2\moban4943\k1\app.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) at Function.Module._load (internal/modules/cjs/loader.js:746:27) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:92:18) at new View (V:\ga2\moban4943\k1\node_modules\express\lib\view.js:42:49) at Function.app.render (V:\ga2\moban4943\k1\node_modules\express\lib\application.js:487:12) at ServerResponse.res.render (V:\ga2\moban4943\k1\node_modules\express\lib\response.js:717:7) at V:\ga2\moban4943\k1\app.js:67:5 at callbacks (V:\ga2\moban4943\k1\node_modules\express\lib\router\index.js:162:37) at param (V:\ga2\moban4943\k1\node_modules\express\lib\router\index.js:136:11)
whats this matter ? how can i fix this code ?

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- 115. The types of template dependencies are a. constraint generating templates b. tuple generating templates c. schema generating templates d. both a and barrow_forwardThe shape class variable is used to save the shape of the forestfire_df dataframe. Save the result to ff_shape. # TODO 1.1 ff_shape = print(f'The forest fire dataset shape is: {ff_shape}') todo_check([ (ff_shape == (517,13),'The shape recieved for ff_shape did not match the shape (517, 13)') ])arrow_forwardCreate a JavaScript Arrow function that meets the following requirements: _missingSpace(string)• Authored using arrow expression syntax (constant name _missingSpace)• The function is passed a string argument• The function inserts a white space between every instance of a lowercase character followed immediately by an uppercase character, and returns the modified string, with whitespaces, back to the caller.• Console log output is NOT permitted.• The function should pass each of the illustrated examples below at a minimum._missingSpace(“”) → “”_missingSpace(“a”) → “a”_missingSpace(“A”) → “A”_missingSpace(“Ba”) → “Ba”_missingSpace(“aB”) → “a B”_missingSpace(“BaB”) → “Ba B”_missingSpace(“GeorgeBrownCollege”) → “George Brown College”_missingSpace(“SheWalksToTheBeach”) → “She Walks To The Beach”_missingSpace(“TheGreatUpset”) → “The Great Upset”arrow_forward
- Which of the following situations will lead to an object being aliased? Select all that apply. O Assigning a string to S1, then using S1 in a function call with header "def foo(x: str) -> None" O Assigning a list to L1, then assigning the result of slicing L1 (i.e., L1[:]) to L2 OAssigning a list to L1, then assigning the result of a copy() method on L1 to L2 O Assigning a list to L1, then assigning L1 to L2 O Assigning a string to S1, then assigning the result of slicing S1 (i.e. S1[:]) to S2 OAssigning a string to S1, then assigning the result of a replace() method on S1 to S2 OAssigning a list to L1, then using L1 in a function call with header "def foo(x: List) -> List" O Assigning two lists to L1 and L2, then assigning the result of adding them to L3arrow_forwardDon't use AI or chatgpt etc for answering!!!arrow_forwardGiven the following program segment. Assume the node is in the usual info-link form with the info of the type int. (list and ptr are reference variable of the LinkedListNode type. What is the output of this program? list = new LinkedListNode (); list.info = 20; ptr = new LinkedListNode (); ptr.info = 28; ptr.link= null; list.link ptr; ptr = list; list = new LinkedListNode (); list.info = 55; list.link = ptr; ptr = new LinkedListNode (); ptr.info = 30; ptr.link= list; list = ptr; ptr = new LinkedListNode (); ptr.info = 42; ptr.link= list.link; list.link= ptr; ptr = list; while (ptr!= null) { } System.out.println (ptr.info); ptr = ptr.link;arrow_forward
- In python: student_dict is a dictionary with students' name and pedometer reading pairs. A new student is read from input and added into student_dict. For each student in student_dict, output the student's name, followed by "'s pedometer reading: ", and the student's pedometer reading. Then, assign average_value with the average of all the pedometer readings in student_dict..arrow_forwardWhat do the urlretrieve and urlopen functions do?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





