Step 1 Create Correct Folder Structure
Most important thing to deploy a NodeJS Application is folder structure that you choose and main files that it should have , if this goes missing deployment is going to fail, below is the folder structure that you would need to follow
All your html files will come under public/js/views folder and js files will come under public/js/viewModels
The nbproject will have project.properties and project.xml file
nodemodule folder will have complete list of node modules as shown below
refer this video on how to download nodemodules
Step 2 www file and port 3000
the www file is located in bin directory , ensure that PORT 3000 is opened
#!/usr/bin/env node /** * Module dependencies. */ var app = require('../app'); var debug = require('debug')('oraclejetwithnodejs:server'); var http = require('http'); /** * Get port from environment and store in Express. */ var port = normalizePort(process.env.PORT || '3000'); app.set('port', port); /** * Create HTTP server. */ var server = http.createServer(app); /** * Listen on provided port, on all network interfaces. */ server.listen(port); server.on('error', onError); server.on('listening', onListening); /** * Normalize a port into a number, string, or false. */ function normalizePort(val) { var port = parseInt(val, 10); if (isNaN(port)) { // named pipe return val; } if (port >= 0) { // port number return port; } return false; } /** * Event listener for HTTP server "error" event. */ function onError(error) { if (error.syscall !== 'listen') { throw error; } var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; // handle specific listen errors with friendly messages switch (error.code) { case 'EACCES': console.error(bind + ' requires elevated privileges'); process.exit(1); break; case 'EADDRINUSE': console.error(bind + ' is already in use'); process.exit(1); break; default: throw error; } } /** * Event listener for HTTP server "listening" event. */ function onListening() { var addr = server.address(); var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; debug('Listening on ' + bind); }
Step 3 manifest.json , setting up Node JS Version
{ "runtime":{ "majorVersion":"6" }, "command": "node ./bin/www", "release": {}, "notes": "Sample Application to run on Oracle Application Container Cloud" }
Remember if the NodeJS version is 6+ still the major version number should be 6
Step 4 package.json
{ "name": "mynodejsapp", "version": "0.0.0", "private": true, "scripts": { "start": "node ./bin/www" }, "dependencies": { "body-parser": "~1.17.1", "cookie-parser": "~1.4.3", "debug": "~2.6.3", "express": "~4.15.2", "jade": "~1.11.0", "morgan": "~1.8.1", "serve-favicon": "~2.4.2" } }
Step 5 Zip the entire package
After all these changes have been made , the entire application need to be zipped example mynodejsapp.zip , please ensure that the Application is running locally , you can use Oracle Netbeans IDE to test the working of the Application
Step 6 Deploying Application on Oracle Application Container Cloud Service
login to MyServices Dashboard and Access Oracle ACCS , The link will be as shown below or might vary depending on data center location
https://apaas.us.oraclecloud.com/apaas/faces/aPaaSRunner.jspx
click on Create Application and Select Node JS
Upload the Zip File and Manifest.json file , ensure that Proper version of Node JS is selected , in our case its version 6 , deployment should happen and application should have an HTTPS url after deployment
Final Result , URL of Deployed Application
Now the newly deployed application should be available on following URL
https://ApplicationName-IdentityDomainName.apaas.us2.oraclecloud.com/
Regards
Madhusudhan Rao