I am working on three files at the moment which are index.js , index.main.js and app.js. I'm using request-context to grab a variable from index.main.js and pass it to index.js.
In app.js (A file I created in my server folder) I have the following code
//full code in app.js
const contextService = require("request-context");
const app = express();
app.use(contextService.middleware("request"));
I have tried running these following commands
npm install --save typescript @types/node @types/react @types/react-dom @types/jest
npm install -D @types/request-context
and also tried using before import
// @ts-ignore
To no avail.
When I check my app.js I notice three dots on the word "require" which shows:
Could not find a declaration file for module 'request-context'. '/home/servertest/Desktop/folder/folder1/src/component_NodeJS/server/node_modules/request-context/lib/index.js' implicitly has an 'any' type.
Try npm install @types/request-context
if it exists or add a new declaration (.d.ts) file containing declare module 'request-context';
ts(7016)
In index.main.js I have the following
async function listFilesInDepth()
{
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucketName = 'probizmy';
const [files] = await storage.bucket(bucketName).getFiles();
const contextService = require("request-context");
console.log('List Of Files Available:');
files.forEach(file =>
{
targetFiles = file.name;
console.log(`-----`+file.name);
});
contextService.set("request:targetFileKey", targetFiles);
return targetFiles;
}
and in index.js I have the following code
const contextService = require("request-context");
const targetFiles = contextService.get("request:targetFileKey");
console.log(targetFiles) //output shows undefined
I'm suspecting the request-context error is why I'm getting undefined as the output. My expected result is for the value of targetFiles to be output on the console log.
Hoping to get some insight on this. Any help would be greatly appreciated! Thank you :)
Edited:
As requested I have included package.json
{
"name": "server",
"version": "0.1.81",
"description": "Server NodeJS For Internel Process",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@google-cloud/storage": "^2.4.2",
"@google-cloud/vision": "^0.25.0",
"@types/jest": "^24.0.15",
"@types/node": "^12.0.12",
"@types/react": "^16.8.23",
"@types/react-dom": "^16.8.4",
"alphabet-generator": "^1.0.1",
"body-parser": "^1.18.3",
"cheerio": "^1.0.0-rc.2",
"cors": "^2.8.5",
"express": "^4.16.4",
"format": "^0.2.2",
"grpc": "^1.19.0",
"multer": "^1.4.1",
"natural": "^0.6.3",
"path": "^0.12.7",
"request": "^2.88.0",
"request-context": "^2.0.0",
"require-all": "^3.0.0",
"require-dir": "^1.2.0",
"string-similarity": "^3.0.0",
"typescript": "^3.5.2"
},
"devDependencies": {
"babel-plugin-root-import": "^6.2.0"
}
}