Got the following error starting Express node:
openssl config failed: error:02001003:system library:fopen:No such
process
The node start anyway.
I am not attempting to use SSL.
Here the starting code:
...
app = Express;
app.set('port', process.env.PORT || config.port);
try {
var server = app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + server.address().address + ':' + server.address().port);
});
} catch (e) {
log.fatal(e);
}
Only happens on deploy server. Running in developer machine starts ok.
The problem was that Express looks for the environment variable OPENSSL_CONF to lookup to SSL configuration file.
The variable OPENSSL_CONF was pointing to a non existence location on the drive.
I removed from the system and the message disappear.
Note: must use a new console to launch the node so environment variable OPENSSL_CONF is not present. Or simple deleted on the current console.
Additional information at github
Removing global environment variable OPENSSL_CONF (leftover from previous troubleshooting) solved my problem.
Running on Windows you might try:
Set environment in local command window and verify problem:
set OPENSSL_CONF=c:\dummy
npm -v
=> you now probably see this ssl error message
Remove environment and verify problem is gone:
set OPENSSL_CONF=
npm -v
=> no ssl error message
Source: https://github.com/npm/npm/issues/17261
Please check the System Variables and confirm if the location of openssl.cnf file listed there is correct. Cross check it and update the location in System Variables.
Related
I'm trying to deploy the Starter Kit of React.js (available here : https://github.com/kriasoft/react-starter-kit) on Openshift. To do that, I modified some little things that I explain here.
First, the logs in Openshift tells me that the import keyword in the servers.js file is not recognized. I think Babel is not used by Openshift at this point.
A workaround for that is mentioned here : How do I modify the node startup command in Open Shift?
So I modified the server.js content (because Openshift run the node server.js command and not the babel-node tools/run start defined in the scripts.start property of package.json) with the recommended content and renamed my base server.js to app.js.
Now, the logs tells me that babel-core is not found so I modified the package.json file to put babel-core and babel-cli in dependencies instead of devDependencies and remove a DEV value of another property.
All the times, when I push my code on Openshift (code of the src folder), the compilation failed at a random time (when dependencies are installed) and it take a long long time. However, when I reboot the cartridge I can see logs I explained.
My current situation is that things are looking better but the problem is the disk space : not enough. That's surprising me because the cartridge can host 1GB and on my local machine all files with dependencies take ~148MB. I tried to delete and recreate the cartridge : the same thing appears.
Does anybody know what can be wrong here ? The fact that the cardridge exceed 1GB is weird...
Thank you all.
Here's the solution... I hope it will save hours for some people !
Set the "production" mode to the cartridge app (so that in don't download so many inodes) :
rhc set-env NODE_ENV=production --app appname
Don't forget to modify config.js :
export const port = process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3000;
export const host = process.env.OPENSHIFT_NODEJS_IP || 'localhost';
export const databaseUrl = 'sqlite:' + process.env.OPENSHIFT_DATA_DIR + 'database.sqlite';
Modify app.js (include the host):
import { port, host, auth, analytics } from './config';
//...
models.sync().catch(err => console.error(err.stack)).then(() => {
app.listen(port, host, () => {
console.log(`The server is running at http://${host}:${port}/`);
});
I am migrating my data back-end to openshift from parse.com.
Step 1. I changed openshift port binding of project into following
//var port = process.env.PORT || 1337;
var port = parseInt(process.env.OPENSHIFT_NODEJS_PORT) || 8080;
var httpServer = http.createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
and folked as my new repo https://github.com/kyawzinsoe/parse-server-example.git
Step 2.
Then I create a gear with my parse-server repo with following command.
rhc app-create myserver nodejs-0.10 mongodb-2 --from-code=https://github.com/kyawzinsoe/parse-server-example.git
But it show 8080 port problem as following
What am I missing? Please help me.
You need use Node 4.1+ with parse server. OpenShift is running 0.10.x
You can use this repo https://github.com/h4t0n/nodejs-4-lts-openshift in order to run Node 4.1+ on your OpenShift app.
Update:
I have set up a deploy to OpenShift button that will do most of the work for you:
you will still need to set up you "appId" and "masterKey" either by editing index.js file or with rhc env set APP_ID=myAppId MASTER_KEY=myMasterKey -a myAppName
This is how you can do it the same thing with rhc tool:
rhc app create parseaio http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-nodejs http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-mongodb --from-code https://github.com/antt001/parse-server-example --env APP_ID=myAppId MASTER_KEY=myMasterKey
for more in-depth instructions, check out my blog post on this topic
Original answer
create app using cartridge from http://github.com/icflorescu/openshift-cartridge-nodejs
paste url from Github page into "Code Anything" textbox at the bottom of the page of application creation Choose a type of application page.
on next page paste https://github.com/antt001/parse-server-example into Source Code textbox, to grab parse example project, modified for openshift settings
add recent MongoDB cartridge as instructed at http://github.com/icflorescu/openshift-cartridge-mongodb
clone your repo from OpenShift
replace "appId" and "masterKey" values in the index.js file with your app id and key.
It works fine, I am running this configuration right now.
Update 2
I have removed the snippet, since it is now on a GitHub repo that I mentioned above.
P.S.
as mentioned by #radzio, there is a problem with compiling native nodejs that requires GCC 4.8, however, this configuration does not need any of this and works as is, it uses bcrypt-nodejs instead of native
Thanks to #ionut-cristian-florescu for custom cartriges
My Problem is solved by #Jiri Fiala's comment that I need to set openshift IP
I'm writing a Node.js express app and want to use environment variables for setting the port on which the server should run.
However, I can't seem to get process.env.PORT to read my PORT environment variable.
I've defined the PORT environment variable using export like so:
export PORT=1234 I've also added this line to the ~/.bash_profile file, but process.env.PORT remains undefined.
When I run echo $PORT in terminal, it displays the value (1234) correctly.
I'm running Node V0.12.7 and OSX El Capitan 10.11.1 and really can't find any extra clues on what might be causing this.
Thanks!
EDIT:
Here's the code executed before trying to assign process.env.port to the port variable
var app = require('../app');
var proxy = require("../proxy");
var http = require('http');
var nconf = require('nconf');
nconf.file(__dirname + "/appConf.json");
var appSettings = require('../appSettings');
var port = normalizePort(process.env.PORT || 8080);
There's a great npm package called dotenv, that will auto-load any environment variables from a file called .env in the same directory as your nodeJS application. This could give you a differentPORT variable project to project, instead of globally defining one PORT across all terminals.
As far as everything else, it sounds like PORT should be there (you even said it was properly echo-ing from command line). Did you run node out of the same terminal as you used echo? The only other issues I can think of are if you didn't restart the terminal you're running your server out of after you modified your ~/.bash_profile, or maybe a simple typo somewhere.
I would have posted this as a comment, but I don't have the score for it.
Seems like there is a function or another object named process, it could cover the NodeJS process object.
I have:
added export NODE_ENV=production to app-root/data/.bashprofile (and echo $NODE_ENV shows production)
Tried rhc set-env NODE_ENV=production -a myapp which generates Setting environment variable(s) ... Server returned an unexpected error code: 501
Created an .openshift/action_hooks directory in my local repo and added the line export NODE_ENV=production to both a start and a pre_start file, committed and pushed to openshift
Tried the .openshift/action_hooks/pre_start_* aswell
Declared a root variable (as tipsed by #JuJoDi below) in the beginning of my server.js file, now it looks lite this:
var express = require('express'),
routes = require('./routes'),
api = require('./routes/api'),
http = require('http'),
path = require('path'),
everyauth = require('everyauth'),
connect = require('connect'),
env = process.env.NODE_ENV ? process.env.NODE_ENV : "process.env.NODE_ENV is null";
I'm then printing out using this route:
app.get('/version', function(req,res){
res.json({
"app.get('env')" : app.get('env'),
"process.env.NODE_ENV" : process.env.NODE_ENV,
"Global env" : env
});
});
What happens is that app.get('env') always returns 'development' and process.env.NODE_ENV is not printed at all (null value)
Has anyone got any ideas why this isn't working?
UPDATE
I created a minimalistic node server, still can't get any env-variables to work on open shift:
var http = require('http');
var port = process.env.OPENSHIFT_NODEJS_PORT || 3000;
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || process.env.OPENSHIFT_INTERNAL_IP || 'localhost';
var env = process.env.NODE_ENV
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('' + process.env.NODE_ENV + "|" + env);
}).listen(port, ipaddress);
I couldn't reproduce this issue. I think the 501 error response that you initially received is the cause of your problems.
You should be able to troubleshoot by running the following from within in your project source folder (add -a YOUR_APP_NAME to the end of each command to run elsewhere):
Check your current list of application tokens:
rhc env list
If you have something listed for NODE_ENV, then clear it:
rhc unset NODE_ENV
Set your NODE_ENV to "production":
rhc env set NODE_ENV="production"
Verify that the value has been set by reloading your server, by running rhc env list, or by connecting to your application over SSH to check the system environment directly:
rhc ssh
env | grep NODE_ENV
Running rhc help env provides a lot of good usage info as well. Depending on how they're written, some servers need to be reloaded in order to fetch the new content.
I think the easiest way to get up and running with MEANStack on OpenShift is to use Yeoman's Angular-fullstack generator. It should automatically configure your environment for you.
That closure does not have access to the process object. Above that try
var env = process.env.NODE_ENV;
then print it with
app.get('/version', function(req,res){
res.json({
"app.get('env')" : app.get('env'),
"process.env.NODE_ENV" : env
});
});
When you run the app, try this:
NODE_ENV=production npm start
Substitute npm start with whatever way you start your app (node server or whatever).
That's the way I change the environment, when I am working locally. Since I usually want it to be development.
Express.js will default app.get('env') to development if process.env.NODE_ENV isn't set.
Update:
Sorry, missed the OpenShift part :/
https://www.openshift.com/developers/openshift-environment-variables
Looks like the environment variables in OpenShift need to go in:
.openshift/action_hooks/build
Using export. Have you tried that?
First i installed the node js with webmatrix and ran a sample node js app. the app was assigned a random port. http://localhost:62369/. After that i installed the express module. As said in their doc. i wrote,
var app = express();
app.get('/',function (req, res) {
res.send('hello world!!');
})
app.listen(3000);
Then i restarted the server. The launched browser was still pointing to http://localhost:62369/ instead of port 3000. Moreover http://localhost:3000/ was not working.
I suggest you to run this code so you can see if you have any problem on saving the code with your IDE:
var app = express(),
port = 4555;
app.get('/',function (req, res) {
res.send('hello world!!');
})
console.log("Server is running on " + port);
app.listen(port);
After that, you need to change the port variable only. It's helpful if you comment what you see after running this code on the console.
make sure that you've saved your code in your file (open it with another editor, maybe something's wrong with your editor), close the command line window and open it again. try to run server. I'm sure the problem is not because of node or express. Try to check everything again.
And also run your server with command line:
cd path/folder
node myFile
I don't know what are you using to run server, but if it's something with UI (in comments you mentioned a click) it can cache your code or something like that. So it's safer to run with commend line.