no such file or directory, scandir '/sql/' issue var sql = new SQLBuilder('SQLServer'); on creating the object of json-sql-builder2 module - node.js

I'm getting this below error on deploying my aws lambda package on node 8.10.0 but it works fine in my local windows.
let modules = tools.walk(path.join(__dirname, `../sql/`));
on logging the _dirname it was showing '/' even though its is 'var/task'
lambda uploaded package has src
src/index.js
sql
sql/somemodules
this folders and files inside the uploaded package.
FYI: lambda package has bundled using webpack.
2019-05-09T04:23:22.996Z 6010d98c-2788-4c96-b972-49361876948c Error: ENOENT: no such file or directory, scandir '/sql/'
at Object.fs.readdirSync (fs.js:904:18)
at Object.walk (/var/task/src/index.js:144899:16)
at SQLBuilder._loadModules (/var/task/src/index.js:144709:23)
at new SQLBuilder (/var/task/src/index.js:144298:8)
at handler (/var/task/src/index.js:76189:15)

Related

node.js reading ts file as js in the npm root directory

I've got a Nodejs CLI written with typescript. It is dynamically reading an external file init.ts.
const {init} = require(initFunctionFile)
The goal is that other packages can run the CLI using their own init.ts file. If init.ts is in a plain directory, it works fine. But if it's in the global npm root directory, or if a package containing init.ts is not stored locally and is executed using npx, I'm getting the error:
~/.nvm/versions/node/v14.9.0/lib/node_modules/package-name/.../init.ts:5
init: async function(command: string, codeDir: string){
^
SyntaxError: Unexpected token ':'
It seems that node thinks the file is js. What is happening here, and what's a better way to do this?

pug.compileFile('./views/transactions/html.pug'); Heroku Node Express. Error: ENOENT: no such file or directory, open

Error: ENOENT: no such file or directory, open './views/transactions/html.pug'
Running my application locally I don't have a problem, once I push to Heroku I get the above error. Locally I am using nodemon to serve my express server. I'm using pug to compile some html to send emails. This is the function that is causing the problem.
pug.compileFile('./views/transactions/html.pug')
Using node Express, with React, serving the static/build files from the same server.
My suspicion is that I need to serve the 'views' directory as when I am running locally my nodemon will be doing this, however, I 'm not sure how to do this.
This is a view of my server.js file.
I have a solution to the error message. I got this from this post about node/heroku filepaths.
The issue was that locally my file path was pointing to the correct file but the online/heroku server needed a different filepath. I have included a picture of the file structure for what it's worth.
function createEmailFilePath(filename) {
const newpath = process.env.NODE_ENV === 'production' ?
path.resolve('emails', 'transactions', filename) :
path.resolve('..', 'emails', 'transactions', filename);
return newpath;
}

Electron file path in package issue

I wonder how to get the correct path to file what should be loaded by fs.readFile:
File to load is in the app's root directory.
Starting the app in cli with npm start
var data = fs.readFileSync('settings.json');
works
After packing and starting electron.exe it will lead to
'Error: ENOENT: no such file or directory'
I can fix this for the packaged app with loading by
var data = fs.readFileSync(path.join(process.resourcesPath, 'app', 'settings.json'));
but then the file isn't found runing the app by npm start.
What is the correct way to determine the path to a file in any environement?

ENOENT Error when WriteFile to public folder in Meteor

So I'm trying to write a pdf file to the public folder of Meteor to serve the file to the client. I deploy my application with mup.
The public folder is located under /opt/your-app/current/bundle/programs/web.browser/app/charts/.
If I try to use fs.writeFile() in this folder it throws the following error: Error: ENOENT: no such file or directory, open '/opt/your-app/current/bundle/programs/web.browser/app/charts/JjMMiHnyptmEPJz5D.pdf'
When I ssh into the server the folder is available. But the file has not been created. The app runs in a docker container that is deployed with Meteor up.

Iin meteor deploy server Error: ENOENT, no such file or directory

in my meteor application I am using node fs to write the file, but when I deployed my application at meteor.com server then I am getting error in meteor logs.
WARNING Error: ENOENT, no such file or directory 'testaudio/server/uploads/6_40_16_340.pcm'
at Object.fs.openSync (fs.js:432:18)
fs = Meteor.npmRequire('node-fs'); in my server and i mentioned the version in packags.json
I am writting file inside /server/uploads/file_name in my application.
I dont know why I am unable to write the file at server. event I tried with full path by using
fullPath = meteor_bootstrap.serverDir that gives path like :-
/appDir/.meteor/local/build/programs/server

Resources