In Node.js, I'm attempting to use fs.mkdirSync() to create a new directory in a remote server/folder structure '\\myserver.com'
My computer (Windows) seems to be connected to this server, have permissions to access it, and is viewable and editable in my File Explorer. fs.mkdirSync() seems to have no issue creating folders locally on my machine, but when I put the server path as the directory, it throws an error
Code:
fs.mkdirSync("\\\\myserver.com\\folder1\\folder2\\new folder")
Error:
{ Error: EPROTO: protocol error, mkdir '\\myserver.com\folder1\folder2\new folder'
at Object.fs.mkdirSync (fs.js:885:18)
at exports.create_new_folder (/file_calling_mkDir.js:107:6)
errno: -71,
code: 'EPROTO',
syscall: 'mkdir',
path: '\\myserver.com\folder1\folder2\new folder' }
What seems to be going wrong here? The folder does not get created and there isn't much documentation on using fs with server paths for me to refer to, making this difficult to solve. Any help would be massively appreciated.
Related
I have made a simple REST API, and I have a react native application where I am trying to call the API with fetch. The server is running on the same computer as the react native application, in my fetch call I used 'fetch('http://10.0.2.2:3000/Users)' which from what I know is the correct way to call it. When I run my react-native application to test if the connection works, I get the following error:
Error: ENOENT: no such file or directory, open 'C:\root\react-native\ReactAndroid\hermes-engine.cxx\Release\21w5t5f5\x86_64\lib\InternalBytecode\InternalBytecode.js'
at Object.openSync (node:fs:584:3)
at Object.readFileSync (node:fs:452:35)
at getCodeFrame (C:\Users\brayd\projects\startscreentest\node_modules\metro\src\Server.js:1004:18)
at Server._symbolicate (C:\Users\brayd\projects\startscreentest\node_modules\metro\src\Server.js:1073:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Server._processRequest (C:\Users\brayd\projects\startscreentest\node_modules\metro\src\Server.js:437:7) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'C:\root\react-native\ReactAndroid\hermes-engine.cxx\Release\21w5t5f5\x86_64\lib\InternalBytecode\InternalBytecode.js'
Has anyone got this error before and know of a a solution? Would really appreciate some help with this, I have been tried almost everything I can think of and at this point I am lost as to what I should do.
I have never seen this error before, I have looked online to see if anyone has posted a solution and found nothing, I have no idea how to solve this error, I have been debugging for hours, and have tried countless things including changing the fetch url, making a new application, etc. I know the api works because I have tested all the routes with curl, I know the fetch statements work because I created a js project and tested the fetch statements. For some reason, its just not working on my react-native application, its either giving me the above error, or if I change the url to something else like 'fetch('http://localhost:3000/Users)' it just gives me 'network connection error'.
You have to create a wamp or nginx server on your computer. Then your API project starts on a server. After that, you can access your pc IP address. Actually, your react native simulator doesn't work on your pc. So you can't access the directly pc IP address.
I am running a node js application with AWS.
This is server less application therefore when I am trying to install through this
https://www.serverless.com/plugins/serverless-offline
Things are working fine till here.. after that when I am trying to run sls offline I am getting this error.
zsh: command not found: sls
Can anybody help me what I am missing here. Also I have places all the access details of my AWS creads in AWS credentials.
I am trying to import images I have stored in a folder called resources located under the server section.
When I place the images in the app folder on my local drive, it works fine, but since this has to be deployed to our live server, it makes things hard to have to copy files back and forth.
The error I get:
Error: ENOENT: no such file or directory, open '../../resources/cp_pdf_logo.png'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at RouteEmails.orderAuth (C:\Development\kaizen\server\routes\emails\file:\C:\Development\kaizen\server\routes\emails\func.js:187:43)
at RouteEmails.sendMail (C:\Development\kaizen\server\routes\emails\file:\C:\Development\kaizen\server\routes\emails\func.js:430:17)
at RouteOrders.orderAuthorizedMail (C:\Development\kaizen\server\routes\orders\file:\C:\Development\kaizen\server\routes\orders\func.js:840:24)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at RequestRouter._routeRequest (C:\Development\kaizen\server\socketController\file:\C:\Development\kaizen\server\socketController\requestRouter.ts:64:34)
at RequestRouter.processMessage (C:\Development\kaizen\server\socketController\file:\C:\Development\kaizen\server\socketController\requestRouter.ts:43:9)
at Socket. (C:\Development\kaizen\server\socketController\file:\C:\Development\kaizen\server\socketController\socketClient.ts:62:7) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '../../resources/cp_pdf_logo.png'
}
Here is an example of my code:
let ordercplogo = this.base64_encode("../../resources/cp_pdf_logo.png")
let orderthankyoulogo = this.base64_encode("../../resources/thankyou_logo.png")
// let ordercplogo = this.base64_encode("/app/resources/cp_pdf_logo.png");
// let orderthankyoulogo = this.base64_encode("/app/resources/thankyou_logo.png");
The commented-out section is what works, but from the image below you can see that I have these files stored inside the app.
Can anyone tell me what I'm doing wrong?
PS. I have also tried to import the images above with
const logo1 = require("../../resources/image.png")
but also doesn't work and throws another error.
Your function probably tries to find the image relative to the working directory. It makes a difference if you were to do cd /; node /app/index.js or cd /app; node index.js. The working directory may be different in your live environment than locally.
There are a number of functions to help you find the path to a file in the built-in path module.
Let's assume you're in a file called routes/companies/a.js:
const { resolve } = require('path');
this.base64_encode(resolve(__dirname, "../../resources/cp_pdf_logo.png"));
// Will find the absolute path to the file.
( path.relative documentation page )
In CommonJS files (files that use require()) the value __filename always refers to the file it's in, rather than the main script file (so /app/routes/companies.a.js in this example) and __dirname is the directory it's in. That's the same value, without the a.js part.
I am trying to convert a firebase-queue worker to send push notification to a cloud function. I am using node-apn to send push notification to iOS devices. It requires setting up a connection which requires me to specify a key.pem file and cert.pem file. These files are present at the same location where the worker js file is present and works without any problem. I moved over the code to a cloud function but I get this error in the Logs console
{ Error: ENOENT: no such file or directory, open './cert.pem'
at Error (native)
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: './cert.pem' } 'Unable to send push notification to iOS device. Socket Error'
Below is how the files are specified and the connection is created in the code
var connectionOptions = {
cert:'./cert.pem',
key:'./key.pem',
production: true
};
var apnConnection = new apn.Connection(connectionOptions);
I have tried specifying the cert file as ./cert.pem and cert.pem but I get a similar error in both the cases. I guess the problem is that the .pem files are not shipped along with the functions.
How can I specify such files in a cloud function?
Your path reference isn't quite right for firebase functions.
It should be:
var connectionOptions = {
cert:__dirname + '/cert.pem',
key:__dirname + '/key.pem',
production: true
};
I've been trying to get my nodejs server process to be monitored by supervisor, however I'm having issues getting supervisord.conf to work. When I deploy, I get the following error:
WARNING: The service crashed at startup or is listening to the wrong port. It failed to respond on port "node" (42801) within 30 seconds. Please check the application logs.
However when I ssh into the dotcloud server and manually start the nodejs process, it runs just fine, indicating that supervisor is failing to start the node instance.
My supervisord.conf looks like this:
[program:node]
command = node /home/dotcloud/current/app/server.js
autostart=true
autorestart=true
And my directory structure is as follows:
.dotcloudignore
dotcloud.yml
.gitignore
app/
app/package.json
app/server.js
app/supervisord.conf
At this point, I can't see what I'm doing wrong, as this appears to be the same directory structure as outlined here, so I'm kind of at a loss as to what the solution is. Any ideas?
Edit:
After trying a supervisorctl status I get the following:
node FATAL Exited too quickly (process log may have details)
I've found that in /var/log/supervisor, I'm getting the following error message:
module.js:337
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module '/home/dotcloud/current/app/server.js'
at Function._resolveFilename (module.js:337:11)
at Function._load (module.js:279:25)
at Array.0 (module.js:484:10)
at EventEmitter._tickCallback (node.js:190:38)
I'm not sure what is causing this.
After investigating the issue, it looks like the issue came from the fact that dotcloud.yml specified approot: app. In that case, it is useful to note that:
/home/dotcloud/code will point to the whole code repository;
/home/dotcloud/current will point to the approot (more specifically, /home/dotcloud/current will be a symlink to the approot, i.e. code/app in that case).
Therefore, supervisord.conf should not contain:
command = node /home/dotcloud/current/app/server.js
But, instead:
command = node /home/dotcloud/current/server.js
The key was in the Node.js logs themselves, since Node.js was complaining about being unable to locate /home/dotcloud/current/app/server.js.