Rectangle 27 9

With express 4 the express boilerplate generator command line was extracted to it's own module 'express-generator' because the generator app did not really share code with express web framework and express and generator app can be released independently.

I guess this was a step into the right direction to decouple the web framework from the boilerplate/skeleton generator since this makes express even more lightweight and leverages tools like yeoman that focus on generating things.

Does that mean 'express-generator' has the same 'core' with 'express' framework,I mean 'express-generator' can do the same thing which 'express' can do?Now I use 'express-generator' instead of 'express' and I have not yet found any difference.

node.js - What is the different between express and express-generator ...

node.js express
Rectangle 27 6

I just had to start PM2 with bin/www instead of app.js. Express generator and everything. How should i know.. \_()_/

Have had an incredibly horrific afternoon trying to solve this problem. Would love to know why bin/www worked while app.js did not.

node.js - PM2 and Nginx: 502 Bad Gateway - Stack Overflow

node.js ubuntu nginx pm2
Rectangle 27 8

When building a MEAN web app you should start by creating an Express application with Express-Generator these commands (assuming you have node and express installed global)

to install the dependencies from the package.json file

.
 app.js
 bin
  www
 models
  home.js
 node_modules
 package.json
 public // your Angular app goes here
 README.md
 routes
  home.js
  users.js
 views

So above we can see the basic structure of the app. You should have something similar after running Express generator. You will take your Angular app and put it into the public folder and run the server with

With an Ionic app you want an app for a phone that someone will, because of that you wont need to add the app to the public folder here. What you will use Express for is to create an api for your app to call. You can create a simple web api with a server.js file that you can run with

In your Angular Factories and Services you can make $http calls directly to your api.

Currently working on a boilerplate to split back and front end of a mean app, this means that you will be able to serve the exact same backend to you android app, ios app and your web app.

Its a work in progress but feel free to check it out for ideas or to start your own separate front and back end MEAN stack. https://github.com/joeLloyd/MEANBoilerPlate

javascript - How would I implement Node.js into an Ionic / Angular app...

javascript angularjs node.js express ionic-framework
Rectangle 27 2

The difference is that with Express 4, a lot of middleware and other things that were not necessary for "core" Express were exported into separate modules. The Express project generator happened to be one of those things.

node.js - What is the different between express and express-generator ...

node.js express
Rectangle 27 77

npm start
node app.js

The solution is to simply rename app.js to anything else except server.js (ie main.js) and reference that in bin/www by pointing to it in the /bin/www file: var app = require('../app'); to var app = require('../main');

The package.json file will get called by ELB when it launches the application server. Here it has the instruction to run the start script node bin/www

This is the bin/www file that gets run. We see the require to ../main and the app.set('port'...)

Then the main.js file that runs the routing and all:

When I created the project, the main.js file was named app.js. The problem this caused was based on the priority ELB start sequences. ELB will launch the application and check first to see if app.js exists -- if it does exist, it runs node app.js, otherwise it will check if package.json exists and try to run npm start. When the main.js had the name app.js ELB tried to start the whole application by running it. However this file doesn't open any ports.

where is that /bin/www file? on the ex2 instance?

figured out the express 4 structure. literally did express inside a blank 'test' folder and updated my /bin/www following the rename. still no dice :/

I update the answer to show the directory structure. I struggled with it a while. You are using ELB (Elastic Beanstalk) right? The directory I show is the whole thing that you upload to ELB. Are you uploading via github or a zip file? For zip you may want to try two things: zip the whole folder recibel in my cas, OR zip the contents within recibel.

ooh thanks for the update. super clear. i did figure it out! so yay. but hopefully the next confused soul has an easier time.

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 76

npm start
node app.js

The solution is to simply rename app.js to anything else except server.js (ie main.js) and reference that in bin/www by pointing to it in the /bin/www file: var app = require('../app'); to var app = require('../main');

The package.json file will get called by ELB when it launches the application server. Here it has the instruction to run the start script node bin/www

This is the bin/www file that gets run. We see the require to ../main and the app.set('port'...)

Then the main.js file that runs the routing and all:

When I created the project, the main.js file was named app.js. The problem this caused was based on the priority ELB start sequences. ELB will launch the application and check first to see if app.js exists -- if it does exist, it runs node app.js, otherwise it will check if package.json exists and try to run npm start. When the main.js had the name app.js ELB tried to start the whole application by running it. However this file doesn't open any ports.

where is that /bin/www file? on the ex2 instance?

figured out the express 4 structure. literally did express inside a blank 'test' folder and updated my /bin/www following the rename. still no dice :/

I update the answer to show the directory structure. I struggled with it a while. You are using ELB (Elastic Beanstalk) right? The directory I show is the whole thing that you upload to ELB. Are you uploading via github or a zip file? For zip you may want to try two things: zip the whole folder recibel in my cas, OR zip the contents within recibel.

ooh thanks for the update. super clear. i did figure it out! so yay. but hopefully the next confused soul has an easier time.

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 1

To access the variable on the client, you'll need to expose it inside of a script tag, there are a few node modules that can help you with it (ex: express-state) https://www.npmjs.com/package/express-state, but you'll need a templating engine to generate the html required for it. You can use a variety of templating engines when working with express. If you use express generators straight out of the box it should come with jade and you can use different options on the generators to use other templating engines. See here for express generator options http://expressjs.com/en/starter/generator.html

javascript - Access server variable in client side (node.js + express)...

javascript node.js express
Rectangle 27 27

An alternative to renaming app.js is to create an elastic beanstalk configuration file. Add a .config file into the .ebextensions folder, for example, .ebextensions/34.config. Change the NodeCommand setting in the namespace aws:elasticbeanstalk:container:nodejs to whatever command you want to run to start the server. For example, this is a minimal .config file to run npm start instead of app.js:

option_settings:
  - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: NodeCommand
    value: "npm start"

Edit: An even easier way - using the AWS console, Configuration/Software has the "Node command" option - just set that to npm start.

Thank @Logan Pickup. That fixed it for me and seems cleaner than messing with the app structure.

I didn't want to change my express structure so the final Edit in this answer was the perfect cure. It's a shame this isn't highlighted in the AWS EB tutorials.

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 27

An alternative to renaming app.js is to create an elastic beanstalk configuration file. Add a .config file into the .ebextensions folder, for example, .ebextensions/34.config. Change the NodeCommand setting in the namespace aws:elasticbeanstalk:container:nodejs to whatever command you want to run to start the server. For example, this is a minimal .config file to run npm start instead of app.js:

option_settings:
  - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: NodeCommand
    value: "npm start"

Edit: An even easier way - using the AWS console, Configuration/Software has the "Node command" option - just set that to npm start.

Thank @Logan Pickup. That fixed it for me and seems cleaner than messing with the app structure.

I didn't want to change my express structure so the final Edit in this answer was the perfect cure. It's a shame this isn't highlighted in the AWS EB tutorials.

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 5

In that there is option to change the default engine from Jade to HTML

var app = require('express')(),
  swig = require('swig'),
  people;

// This is where all the magic happens!
app.engine('html', swig.renderFile);

app.set('view engine', 'html');

@RiteshDhuri: I have provided the link for reference, I have just copied the snippet and pasted it here.

node.js - Express generator with Swig - Stack Overflow

node.js express swig-template
Rectangle 27 3

At the Elastic Beanstalk console, inside your app-environment section, there is a Configuration menu item on your left side (right bellow Dashboard menu option). If you click there, you will find many configuration options. Click at Software Configuration and then define which is your node command. There explain the order of commands it tries indeed: "Command to start the Node.js application. If an empty string is specified, app.js is used, then server.js, then "npm start" in that order"

"scripts": {
    "start": "NODE_ENV=production && node ./bin/www"

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 3

At the Elastic Beanstalk console, inside your app-environment section, there is a Configuration menu item on your left side (right bellow Dashboard menu option). If you click there, you will find many configuration options. Click at Software Configuration and then define which is your node command. There explain the order of commands it tries indeed: "Command to start the Node.js application. If an empty string is specified, app.js is used, then server.js, then "npm start" in that order"

"scripts": {
    "start": "NODE_ENV=production && node ./bin/www"

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 48

With Express 4, the application generator was removed and is now available as 'express-generator.' So you need to npm install -g express-generator instead.

why npm commands takes too much time in my ubuntu 14.04 64 bit :( sometime it stucks saying nothing for a long time

express
The program 'express' is currently not installed. You can install it by typing: sudo apt-get install node-express

node.js - install express with npm - Stack Overflow

node.js ubuntu express npm
Rectangle 27 2

In case anyone did the silly thing i did, make sure your 'bin' folder is committed if you are using express. I had mine in my '.gitignore' file and this is why I was getting a 502 error.

Just remove '/bin' from '.gitignore', commit, and the deploy changes to EB.

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 2

In case anyone did the silly thing i did, make sure your 'bin' folder is committed if you are using express. I had mine in my '.gitignore' file and this is why I was getting a 502 error.

Just remove '/bin' from '.gitignore', commit, and the deploy changes to EB.

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 31

npm install -gd express-generator

The original express with cli, now the cli split into separate express-generator package. Originally generated by the project is running express node app.js, because httpserver relevant code in app.js, and now this part of the code to the project directory bin/www below, app.js retain only achieve app logic code, you need to run the bin/www. Just a very simple application and refinement package dependency version changes.

node.js - Express command not found - Stack Overflow

node.js command-line express
Rectangle 27 329

With the release of Express 4.0.0 it looks like you need to do sudo npm install -g express-generator.

sudo is not required for reasoned mentioned and will still work. stackoverflow.com/questions/4938592/

Bummer, not even official documentation mentions it. ;-)

Why on earth did I find out about this HERE???!?!?!?!

node.js - Express command not found - Stack Overflow

node.js command-line express
Rectangle 27 1

app.set('port', 8081);

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 1

If you use port 8081 for running your express app and use sudo for running node server, Your application will be accessed directly from elasticbean url without port numbers otherwise it will display 502 Gateway error from nginx.

Create file - .ebextensions/nodecommand.config and put option settings below -

option_settings:
  aws:elasticbeanstalk:container:nodejs:
    NodeCommand: sudo pm2 start server.js (server command with sudo ie. sudo node /bin/www)

You can create another file for container commands - .ebextensions/01_init.config and put desired commands which will be run before deployment. For example -

container_commands:
  01_node_v6_install:
    command: sudo curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
  02_install_node:
    command: sudo yum -y install nodejs
  03_npm_install_gulp_webpack:
    command: sudo npm install -g gulp webpack pm2
  04_npm_install:
    command: sudo npm install
  05_webpack_run:
      command: sudo webpack

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express
Rectangle 27 1

app.set('port', 8081);

node.js - 502 Bad Gateway Deploying Express Generator Template on Elas...

node.js amazon-web-services nginx express