problems deploying node.js application - node.js

I'm having trouble deploying node.js application to appfog, according to the instruction on appfog i made a new package.json file with the next content:
{
"name":"<my app name>",
"version":"0.0.1",
"dependencies":{
"express":""
}
}
and a new app.js file with the next content:
var app = require('express').createServer();
app.get('/', function(req, res) {
res.send('Hello from AppFog');
});
app.listen(process.env.VCAP_APP_PORT || 3000);
then i wrote the command:
$ npm install
and got the next warning:
npm WARN package.json methods#0.0.1 No README.md file found!
and when i try to push my app to appfog i get the next message:
No such file or directory - /Applications/Flip Player.app
what am i missing here? am i doing something wrong?
Thanks.

Ignore the WARN, as it's just a signal to package maintainers that they should add a Readme.
Your real bug is that your app is missing Flip Player. Somehow, you've added Flip Player to your repository, or indicated it was required with adding it.
If you just started your project, I would try blowing away your git repository and then creating a new one, this time being careful to leave Flip Player out.

Related

can't load files when trying to publish my threejs project on github pages

I've been experimenting with react three fiber and wanted to publish a project on github pages. I did a build of my project and deployed it on pages. I get an error in the console that it can not load my files:
main.bb26e057.js:1 Failed to load resource: the server responded with a status of 404 ()
Here is a link to the repository: https://github.com/olvard/repossumtory/tree/main/possumtory ,
Here is a link to the pages site: https://olvard.github.io/repossumtory/possumtory/build/
I've tried fiddleing with different filepaths but i don't understand why npm run build would give me incorrect filepaths anyways.
Would be grateful for any help.
Try providing the homepage property in the package.json of the React App.
In your case, https://olvard.github.io/repossumtory/possumtory/build/ is the start url.
So modify include this line in your package.json.
"homepage": "https://olvard.github.io/repossumtory/possumtory/build/",
Edit:
Adding to your comment: The model fails to load at the first attempt because of your model.js on the last line.
It should be useGLTF.preload('opossum.glb') instead of useGLTF.preload('/opossum.glb')
I would recommend using a package called gh-pages. It's a scripted way of uploading your site using the pages functions of GitHub and also supports custom configuration options on commit.
All you need to do is run:
npm install gh-pages --save-dev
Then create a new file. Inside this file simply insert this code:
var ghpages = require('gh-pages');
ghpages.publish('path-of-dir-to-commit', function(err) {
if(err) {
console.log(err);
} else {
console.log("success");
});
You can read more on the npm site for the configuration options such as naming the repo it generates if non is found, etc.

React / Express - Error: ENOENT: no such file or directory, stat '/app/build/index.html'

Please see edits below
Please put me out of my misery here. I've spent hours looking through docs and trying different approaches found on this site. I am getting this error when heroku tries to build after pulling code from github:
Error: ENOENT: no such file or directory, stat '/app/build/index.html'
I have my client code in root and my express server code in /server.
Node is being started from the root package.json (e.g. node server/index.js).
If I bash into heroku I can see the /build/index.html file.
app.use(express.static(path.resolve(__dirname, '../build')));
app.get('*', (req, res) => {
res.sendFile(path.resolve('build/index.html'));
});
EDIT
Something else that is curious. If I set the path like so I can browse my images in /build folder on localhost:5000 (same path off of root) but I still get the same error in prod.
app.use(express.static(path.join(__dirname, '/../build')));
EDIT 2:
It turns out that I needed to add a static reference to 'public'. Argh!
I can now see index and anything else in the build directory working.
However, there is no reference to the static/js files that are created during the build and thus the page is empty. I can see them on the server in bash prompt.
app.use(express.static(path.join(__dirname, '..', 'build')));
app.use(express.static('public'));
app.use((req, res, next) => {
res.sendFile(path.join(__dirname, '..', 'build', 'index.html'));
});
I never did find the issue so I scaled it back and had another go of it. Ultimately I don't think you even need to reference the index.html file. At the root level I have server.js. In that file I simply reference the client/build after my route files and this acts as the default for anything not found in the route:
app.use(express.static("client/build"));
I hope this will help other people with this issue. I ran into this error this week and I solved it. In my case it has nothing to do with the client/build/index.html path. And I bet it's the same thing in your case as well.
Please bear with me and go through these points first to understand where the problem comes from:
The problem is that when you create your react app, it somehow runs a git init command automatically. You end up with 2 git folders: one for the Express backend and another for your react client folder.
The result is that when you do commit your changes, those in the client folder are not being pushed to heroku.
To convince yourself that this is the case, run these commands in your terminal at the root of your project:
a) heroku run bash
b) cd into the client folder
c) ls client
if at this stage you don't see the content of your client folder, then that's what caused the problem in the first place.
Now for the remedy:
Go to your terminal and run these commands (credit goes to: Content of create-react-app is not pushed in github)
mv client subfolder_tmp
git submodule deinit client
git rm --cached client
mv subfolder_tmp client
git add client
now make changes in your client folder and then push them to heroku (git add . , git commit -m "", git push heroku master)
Let me know if this helps, I know I solved my problem this way.

Cannot get correct static files after refreshing except index page

When I refresh page on index route (/) and login page (/login), it works fine.
However, my website gets error as I refresh on other routes, for example /user/123456.
Because no matter what the request is, the browser always gets HTML file.
Thus, both of the content in main.css and main.js are HTML, and the browser error.
I have already read the README of create-react-app.
Whether I use serve package ($serve -s build -p 80) or express, it will produce the strange bug.
Following is my server code:
//server.js
const express = require('express');
const path = require('path');
app.use(express.static(path.join(__dirname, 'build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
const PORT = process.env.PORT || 80;
app.listen(PORT, () => {
console.log(`Production Express server running at localhost:${PORT}`);
});
Edit: I have figured out where caused the problem.
I created a new project, and compared it to mine. The path of static files in the new project is absolute, but in my project is relative.
As a result, I delete "homepage": "." in the package.json.
//package.json
{ ....
dependencies:{....},
....,
- "homepage": "."
}
Everything works as expected now. How am I careless...
I have figured out where caused the problem.
I created a new project, and compared it to mine. The path of static files in the new project is absolute, but in my project is relative.
As a result, I delete "homepage": "." in the package.json.
//package.json
{ ....
dependencies:{....},
....,
- "homepage": "."
}
Everything works as expected now. How am I careless...
If your route /user/** is defined after app.get('/*', ... it might not match because /* gets all the requests and returns you index.html.
Try without the * or declare the other routes before.
First, I thought you misunderstood the server part. In your case, you use serve as your server. This is a static server provided by [serve]. If you want to use your own server.js, you should run node server.js or node server.
I also did the same things with you and have no this issue. The followings are what I did:
create-react-app my-app
npm run build
sudo serve -s build -p 80 (sudo for port under 1024)
And I got the results:
/user/321
I guessed you might forget to build the script. You can try the followings:
remove build/ folder
run npm run build again
Advise: If you want to focus on front-end, you can just use [serve]. It will be easy for you to focus on what you need.

Failed exitCode=-4071

I am following this guide. Having problem deploying to azure.
https://learn.microsoft.com/en-us/azure/app-service-web/app-service-web-nodejs-sails#step-3-configure-and-deploy-your-sailsjs-app
Full Error
remote: Failed exitCode=-4071, command="D:\Program Files (x86)\nodejs\6.9.1\node.exe" "D:\Program Files (x86)\npm\3.10.8\node_modules\npm\bin\npm-cli.js" install --production
also
remote: npm ERR! EINVAL: invalid argument, rename 'D:\home\site\wwwroot\node_modules\.staging\spdx-license-ids-3f30671f' -> 'D:\home\site\wwwroot\node_modules\sails-hook-grunt\node_modules\grunt-contrib-cssmin\node_modules\maxmin\node_modules\pretty-bytes\node_modules\meow\node_modules\normalize-package-data\node_modules\validate-npm-package-license\node_modules\spdx-correct\node_modules\spdx-license-ids'
Thanks
I do a demo following the tutorials that you mentioned. It works correctly on my side. I used node.js v7.9 locally. If it is possible, please have a try to update the node.js version to latest locally. The following is my details steps.
1.Following the document to install Sails and create a demo project
$npm install sails -g
$sails new test-sails-project
2.go to localhost:1337 to see your brand new homepage
$ cd test-sails-project
$ sails lift
We can check that it works correctly in the local
4.Following the document step by step
a.Add iisnode.yml file with the following code in the root directory
loggingEnabled: true
logDirectory: iisnode
b.set port and hookTimeout in the config/env/production.js
module.exports = {
// Use process.env.port to handle web requests to the default HTTP port
port: process.env.port,
// Increase hooks timout to 30 seconds
// This avoids the Sails.js error documented at https://github.com/balderdashy/sails/issues/2691
hookTimeout: 30000,
...
};
c.hardcode the Node.js version you want to use. In package.json
"engines": {
"node": "6.9.1"
},
5.Create a Azure WebApp on the Azure portal and get the profile.
6.Push the code to the Git remote and check from the Azure portal.

node app.js localhost not working

on WINDOWS ...after install express-seed and node.js for the "blog" tutorial, i get the same cmd prompt after typing node app.js.
another time i got body parser and error handling errors
i tried alot of solutions, even had a local host run with another tutorial, but i would like to run from the blog tutorial due to some slight differences of the set-up.
Of course im a newb, and i know theres tons of answers on the forum, but none are correcting my issue...please help.
and everytime i try to post my report on here it errors me saying i have to indent each line 4 spaces. im just losing in general.
Is there a step im missing? all the tut's say just do 'this' and 'this' and i have a local host running so i can make changes to views. any help?
// Module dependencies.
var express = require('express');
var app = express.createServer();
// Configuration
app.configure( function() {
});
// Routes
app.get('/', function(req, res) {
res.send('Hello World');
});
app.listen(3000);
what version of node & express are you running?
From the command line you can check with:
node --version
and
express --version
From your code, it looks like an older version of express (version 3 or less), but I'm betting you didn't specify the version on the npm install, which will give you the latest version (4+). There's a lot of breaking changes between those versions, so you can't run old code with the new framework successfully. My bet is that your blog tutorial hasn't been updated to express 4.x yet.

Resources