When we looked at the creation of a dynamic express site we saw
npm install express-generator -g
If you did it then, you don't have to redo it.
The -g flag above looks after that. And remember:
You may need to be an administrator to achieve the required
permissions. On Linux or OSX this may be done with
sudo, on Windows you might need to run
cmd in administrator mode.
Now let us create the application
$ express --view=pug nodeOne
create : nodeOne/
create : nodeOne/public/
create : nodeOne/public/javascripts/
create : nodeOne/public/images/
create : nodeOne/public/stylesheets/
create : nodeOne/public/stylesheets/style.css
create : nodeOne/routes/
create : nodeOne/routes/index.js
create : nodeOne/routes/users.js
create : nodeOne/views/
create : nodeOne/views/error.pug
create : nodeOne/views/index.pug
create : nodeOne/views/layout.pug
create : nodeOne/app.js
create : nodeOne/package.json
create : nodeOne/bin/
create : nodeOne/bin/www
change directory:
$ cd nodeOne
install dependencies:
$ npm install
run the app:
$ DEBUG=nodeone:* npm start
Having done that we will set it up to use git as a matter of good habit
cd nodeOne git init echo 'node_modules/' > .gitignore echo 'package-lock.json' > .gitignore git add . git commit -m 'initial commit præ festum'
Please notice that the content of the node_modules,
the modules we don't write ourselves, is external software, and
we don't need it in our repo. It's taken care of via
npm install
We want this app to be hosted, so go to https://www.heroku.com/ and create a free account. When you have done that, install the Heroku Toolbelt, a command line interface. It will prove most useful. Let us do
$ heroku apps:create Creating app... ! ▸ Invalid credentials provided. heroku: Press any key to open up the browser to login or q to exit: Logging in... done Logged in as nml@acm.org Creating app... done, ⬢ tranquil-bastion-58605 https://tranquil-bastion-58605.herokuapp.com/ | https://git.heroku.com/tranquil-bastion-58605.git
And then deploy by
$ git push heroku master Enumerating objects: 20, done. Counting objects: 100% (20/20), done. Delta compression using up to 4 threads Compressing objects: 100% (16/16), done. Writing objects: 100% (20/20), 11.03 KiB | 2.76 MiB/s, done. Total 20 (delta 2), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Node.js app detected remote: remote: -----> Creating runtime environment ... ... remote: remote: Verifying deploy... done. To https://git.heroku.com/tranquil-bastion-58605.git * [new branch] master -> master
So, at this point we have a remotely hosted Node.js app with not much in it. But still.