JulienG
JulienG

Reputation: 188

Cannot find module 'ibmbluemix' on starting application on ibm cloud

I start recently my first nodeJs application on IBM blumix, in following these tutorial http://ibm-bluemix.coderpower.com/#/warmup/55e07bf49924f792327901cd/code. i following the instruction but when I start my application I have the error Cannot find module 'ibmbluemix'

I have the same code as the tutorial, I almost feel that the ibm bluemix module is not installed ... on the cloud ibm bluemix.

Here is the code package.json

{
"name": "NodejsStarterApp",
"version": "0.0.1",
"description": "A sample nodejs app for Bluemix",
"scripts": {
    "start": "node app.js"
},
"dependencies": {
    "express": "4.12.x",
    "cfenv": "1.0.x"
},
"repository": {},
"engines": {
    "node": "0.12.x"
} 
}

app.js

    var express = require('express');
    var ibmbluemix = require('ibmbluemix');
    var config = {
    applicationId:"FirstAppli",
    applicationRoute:"firstappli.mybluemix.net"
   };
   // cfenv provides access to your Cloud Foundry environment
   // for more info, see: https://www.npmjs.com/package/cfenv
   var cfenv = require('cfenv');

   // create a new express server
   var app = express();

   // serve the files out of ./public as our main files
   app.use(express.static(__dirname + '/public'));

   var router = express.Router();
   router.get('/', /* @callback */ function(req,res){
            ibmbluemix.initialize(config).then(/* @callback */ function(success)      {
                res.json({ message : 'sdk initialised' });
            },
            /* @callback */ function(err){
                res.json({ message : 'sdk error' });
            });
        });

    app.use('/api', router);

    // get the app environment from Cloud Foundry
   var appEnv = cfenv.getAppEnv();

   // start server on the specified port and binding host
   app.listen(appEnv.port, '0.0.0.0', function() {

    // print a message when the server starts listening
   console.log("server starting on " + appEnv.url);
  });

the log on starting

Starting app instance (index 0) with guid 8a0df22f-7c18-476f-8dc0-91c3db946ac6
Updated app with guid 8a0df22f-7c18-476f-8dc0-91c3db946ac6 ({"state"=>"STARTED"})
Detected 1024 MB available memory, 512 MB limit per process (WEB_MEMORY)
Recommending WEB_CONCURRENCY=2
Activating app management utilities: devconsole, shell, inspector
2015/10/27 10:46:52 authenticator url is detected as https://api.ng.bluemix.net/v2/apps/8a0df22f-7c18-476f-8dc0-91c3db946ac6/env
2015/10/27 10:46:52 The application base path is detected as /home/vcap
2015/10/27 10:46:52 Starting the proxy agent on port 61392
2015/10/27 10:46:52 Begin to start the runtime...
Starting utility: devconsole...
Adding proxy entry with: {"type": "http-forward", "backend": "127.0.0.1:8788", "host": "*", "uri_prefix": "bluemix-debug/manage"}
2015/10/27 10:46:52 Catch event "/home/vcap/app/.app-management/bin/proxy.config": WRITE. Reload the registry.
Starting utility: shell...
Adding proxy entry with: {"type": "http-forward", "backend": "127.0.0.1:8789", "host": "*", "uri_prefix": "bluemix-debug/shell"}
2015/10/27 10:46:52 Catch event "/home/vcap/app/.app-management/bin/proxy.config": WRITE. Reload the registry.
Starting utility: inspector...
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   1132   828 ?        S<s  10:46   0:00 wshd: 192t1kppgo2    
vcap        29  0.0  0.0 270040  5408 ?        S<sl 10:46   0:00 .app-management/bin/proxyAgent
vcap        35  0.0  0.0  19592  3452 ?        S<   10:46   0:00 bash /home/vcap/app/.app-management/handlers/start-inspector/run
vcap        45  0.0  0.0  19596  3408 ?        S<   10:46   0:00 bash /home/vcap/app/.app-management/scripts/start 61393
vcap        72  0.0  0.0 677992 25228 ?        R<l  10:46   0:00 /home/vcap/app/.app-management/node/bin/node bin/dev.js bluemix-debug/manage 8788
vcap        88  0.0  0.0 677992 23480 ?        R<l  10:46   0:00 npm                                                                         
vcap       113  0.0  0.0 611432 20688 ?        R<l  10:46   0:00 /home/vcap/app/.app-management/node/bin/node server.js bluemix-debug/shell 8789
vcap       145  0.0  0.0  19588   292 ?        R<   10:46   0:00 bash /home/vcap/app/.app-management/handlers/start-inspector/run
vcap       146  0.0  0.0  17172  2472 ?        R<   10:46   0:00 ps aux
Adding proxy entry with: {"type": "http-forward", "backend": "127.0.0.1:8790", "host": "*", "uri_prefix": "bluemix-debug/inspector"}
2015/10/27 10:46:52 Catch event "/home/vcap/app/.app-management/bin/proxy.config": WRITE. Reload the registry.
> [email protected] start /home/vcap/app
> node app.js
node-inspector is active. Visit the web page to start debugging.
module.js:338
    throw err;
          ^
Error: Cannot find module 'ibmbluemix'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/vcap/app/app.js:11:18)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
npm ERR! Linux 3.19.0-25-generic
npm ERR! argv "/home/vcap/app/vendor/node/bin/node" "/home/vcap/app/vendor/node/bin/npm" "start"
npm ERR! node v0.12.7
npm ERR! npm  v2.11.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node app.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node app.js'.
npm ERR! This is most likely a problem with the NodejsStarterApp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node app.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls NodejsStarterApp
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR!     /home/vcap/app/npm-debug.log
2015/10/27 10:46:53 Fail to start the application runtime: The runtime cannot be started. Error: Runtime start script returns error 'exit status 1'. Please check the application logs for more details.
Restarting the runtime in debug mode...
scripts/stop: line 27: kill: (88) - No such process
kill -9 88
scripts/stop: line 32: kill: (88) - No such process
Starting app with 'node --debug=5858  app.js '
Debugger listening on port 5858
module.js:338
    throw err;
          ^
Error: Cannot find module 'ibmbluemix'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/vcap/app/app.js:11:18)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
firstappli.mybluemix.net - [27/10/2015:11:01:33 +0000] "GET /bluemix-debug/manage/tools/runtime HTTP/1.1" 200 0 69 "-" "Jakarta Commons-HttpClient/3.1" 108.168.250.153:11163 x_forwarded_for:"198.11.229.213" vcap_request_id:2ce77b66-4cc0-403d-6558-a020a23e4b93 response_time:0.259158396 app_id:8a0df22f-7c18-476f-8dc0-91c3db946ac6

I don't understand, I've not tried to test the code in local but i'm surprise that nobody on internet had the same error that me. Maybe I have forgotten something obvious... Thanks for your help!

PS : I have not use the default space created but I create a new one (otherwise I cant't create node application), maybe there is some repercussion...

Upvotes: 2

Views: 1284

Answers (1)

Alex da Silva
Alex da Silva

Reputation: 4590

You need to add ibmbluemix as a dependency in your package.json file:

{
"name": "NodejsStarterApp",
"version": "0.0.1",
"description": "A sample nodejs app for Bluemix",
"scripts": {
    "start": "node app.js"
},
"dependencies": {
    "express": "4.12.x",
    "cfenv": "1.0.x",
    "ibmbluemix": "1.0.0"
},
"repository": {},
"engines": {
    "node": "0.12.x"
} 
}

If you want to try your application locally run the following commands after changing package.json file:

# npm install
# node app.js

Upvotes: 1

Related Questions