nodejitsu 400 Error: ENOENT, open '/opt/run/snapshot/package/images/tmp/72118-89rld0.png - node.js

I'm using nodejitsu to deploy a simple image upload program with express. In my code I've changed the default upload directory by following command
app.use(express.bodyParser({
uploadDir: __dirname + "/images/tmp"
}));
It's working fine on my localhost but when I'm using nodejitsu I'm getting this error
400 Error: ENOENT, open '/opt/run/snapshot/package/images/tmp/72118-89rld0.png.
Can anybody tell me how to make it work on nodejitsu as well? Actually I'm new to node as well as nodejitsu.

I had the same problem. Try to check directory at application start:
var fs = require('fs'),
upload = __dirname + "/images/tmp";
fs.exists(upload, function (exist) {
if (!exist) {
fs.mkdir(upload);
}
});
It was helpful for me, may be it would helpful for you.

make sure that directory /opt/run/snapshot/package/images/tmp/ exists. Otherways just mkdir those directory

At first check that the directory exist or not. If not then create it and follow the command
sudo jitsu deploy
I think the problem will be solved.

Related

Node/Git Bash, distorted file path when starting server. Bug or user error?

I'm following along with an example mean stack project. Node/nodemon is experiencing issues in git bash where it produces a throw error when I try to start the server.
Error: Cannot find module 'C:\Users\Emma\desktop\trainingapprc\app.js'
The main directory is called trainingapp, and below it should be src\app.js. Nodemon is leaving out a "\s" between the root directory and src, causing the error. When I run the server with just node, it forgets the src folder completely:
Error: Cannot find module 'C:\Users\Emma\desktop\trainingapp\app.js'
I pulled the example project from github and it does not have this error, even though the directory tree is exactly the same except for the directory name.
I'm new to coding so I'm not sure how to proceed. Is this a bug or user error?
1.Comment out Lines In app.js:
var router = require('./api');
app.use('/api', router);
2.place a . in the code ../public :
app.use('/', express.static('../public'));

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;
}

Error finding html file with fly

I am deploying my first website where I used nodejs in the backend. I am facing an issue for which I have not been able to find a solution for. The website is running perfectly localy and I deployed it a first time with heroku (free version), there was no problem at all.
I just paid for a vps so I would be able to deploy my application with flightplan. Everything works and the website is correctly deployed to the VPS, but when I try to access it with "ip-address:port" I get the following error:
Error: ENOENT: no such file or directory, open './views/base.html'.
Would anyone have an idea on how this happened?
The line that calls the file is:
var file = fs.readFileSync("./views/base.html", "UTF8");
res.status(200).send(file);
Thanks for your help !
Edit:
In the server.js file I use the following line to 'hide' the files in the frontend, could it have something to do with that?
app.use('/webapp', express.static(path.join(__dirname, '/views')));
Found the solution, I don't know why, but the path didn't seem to work properly. Anyway I used
var file = fs.readFileSync(__dirname + "/../views/login.html", "UTF8");
which worked fine

Setting Up Node.js App Directory

I'm completely new to using Node.js and even utilizing the command line, so this question may be extremely elementary, but I am unable to find a solution.
I am trying to set up an app directory using Node.js and NPM. For some reason, whenever I try to use the port:5000 I get a "Cannot GET/" error. My question is, why is my setup for my app directory not working?
I have installed connect and serve-static, and yet it will not retrieve files and listen on port 5000. I have created a server.js file in my user, kstach1. Here is the code I have within that file:
var connect = require('connect');
var serveStatic = require('serve-static');
var app = connect();
app.use(serveStatic('../angularjs'));
app.listen(5000);
So, I don't quite understand why this won't reference my folder of angularjs, where I want to store my app. I have tested it by adding a file within the folder called test.html, and entered localhost:5000/test.html, and still get the "Cannot GET/test.html" error.
I know that Node is working correctly because I can enter scripts into the command line and they give the correct output. I do this as a user (kstach1).
The only thing I can think of that I may be doing wrong, is where my files are located. I have the angularjs folder located in the root user folder on my Mac (kstach1), as well as the server.js file. Is this incorrect? If this is not the issue, is it because of where Node is installed (usr/local/bin/node)? My research to this point has led me to think that my problem could also be that I need to add the installation directory to my path. However, I don't want to mess with this unless I know that is the case.
Any help would be greatly appreciated.
I did a little research on the serve-static package and copied the code you provided.
My project folder is located at "C:\teststatic" and the folder with the static files is: "C:\angularjs", also using "text.html" that is located in the 'angularjs' folder.
When running the code you provided and going to localhost:5000 it indeed returns "Cannot GET/". This is most likely because there is no "/" file declared.
Going to localhost:5000/test.html works for me, so you could try setting a "/" like this:
app.use(serveStatic('../angularjs', {'index': ['test.html', 'index.html']}));
And see if that works for you. If not, you should double check directory names / locations.
EDIT:
From reading the comment you posted: try this instead:
app.use(serveStatic('angularjs'));
I suggest moving your angularjs folder up into your main project's directory in a public/ folder. Its a pretty standard convention to have all of your static assets in public/. You can then use the path module to automatically resolve your path, inserting this where you have '../angularjs': path.join(__dirname, 'public').
So, your code would look like this:
var connect = require('connect');
var serveStatic = require('serve-static');
var app = connect();
var path = require('path');
app.use(serveStatic(path.join(__dirname, 'public'));
app.listen(5000);
And, your directory structure would look like this:
server.js
public/
angularjs/
test.html
You should then be able to use localhost:5000/angularjs/test.html to view your test.html

How to upload file using easy-ftp in node?

I am trying to upload a file into my hosting server using node and easy-ftp.
I try with the following code:
var EasyFtp = require ("easy-ftp");
var ftp = new EasyFtp();
var config = {
host:'homexxxxx.1and1-data.host',
type:'SFTP',
port:'22',
username:'u90xxxx',
password:"mypass"
};
ftp.connect(config);
ftp.upload("/test/test.txt", "/test.txt", function(err){
if (err) throw err;
ftp.close();
});
No error message but no file uploaded
I tried the same using promises
const EasyFTP = require('easy-ftp-extra')
const ftp = new EasyFTP()
const config = {
host:'homexxxxx.1and1-data.host',
type:'SFTP',
port:'22',
username:'u90xxxx',
password:"mypass"
};
ftp.connect(config);
ftp.upload('/test.txt', '/test.txt')
.then(console.log)
.catch(console.error)
ftp.upload()
The same issued. No file is uploaded. No error in node console.
The config is the same used in filezilla to transfer files. SFTP protocol. Everything working well with filezilla.
What I am doing wrong?
Looks like you may have a path problem over here.
"/test/test.txt"
The path specified will try to take file from root folder like "c:\test\test.txt".
Assuming you want the file to be taken from your project folder try this path:
"./test/test.txt"
Other things in your code are precisely the same as in mine and mine works.
For me, it was just silently failing, and intelli-sense was not available.
npm remove easy-ftp
npm install easy-ftp
npm audit fix --force until no more vulnerabilities
Afterwards, intelli-sense was available and it started working.

Resources