Note for 2020: MERN stack is going out of style, as this was originally written in 2016 😱
If you haven't checked out the MERN project, do yourself a favor and check it now and enjoy some next level javascript architecture and tooling!
Though installation and firing up a dev environment were a piece of cake, I struggled getting the project to run in any sort of production environment. I tried zeit/now but got tons of npm errors on upload. Then went back to old faithful - Heroku.
Here is how to successfully deploy it to Heroku:
Create your app on Heroku and add your new git remote to your project.
Remove the following lines from the
.gitignore
:public/* static/dist static/css/app.min.css
Heroku obviously needs to see those files, and since it relies on git we must include them.
Change the
entry
line inwebpack.config.prod
to this:entry: ['babel-polyfill', __dirname + "/client/index.js"] ,
In
package.json
copy ALL of thedevDependencies
to the normaldependencies
tree.Heroku has a configuration to avoid this, but I haven't looked into it much.
Also in
package.json
change thestart
script to this:"start": "cross-env NODE_ENV=production MONGO_URL=yourMongoURL node index.js",
Not sure this next step is 100% necessary but I'm using modulus.io (free for small projects yay!) and this tutorial suggests it. So I added this line in
server.js
just above themongoose.connect(..)
bit:const db = mongoose.connection; db.on('error', console.error); db.once('open', function (res) { dummyData(); //put this here instead of inside mongoose.connect });
Generate a minified bundle with
npm run build
git add .
andgit commit -m 'heroku prep'
git push heroku master
takes sip of beer...
And there you have it! An isomorphic JavaScript app using React and Redux on Heroku!
P.S. Thanks to the #Hashnode crew for putting out the awesome mern project, it is very very cool!