===== Node.js =====
==== Installation ====
== Node.js Server ==
At most follow this tutorial: https://devcenter.heroku.com/articles/node-websockets
- BUGS: **Foreman** is not found and **Bad file descriptor** error. Solutions: \\ http://jasonwatmore.com/post/2013/11/20/Getting-Foreman-working-on-Windows-7-after-installing-the-Heroku-Toolbelt.aspx
== Hot Code-replacement ==
When the server-code is changes, then the node.js app should be restarted. \\
To achieve hot-code-replacement the node.js app should be run differently: by using the tool **nodemon**.
To install nodemon on server do
sudo npm install -g nodemon
It then should be used as following to start a node.js application named "server.js"
nodemon server.js
==== Heroku ====
Heroku is the hosting, which is able to host node.js apps too!
The howto about deploying the app is here: https://devcenter.heroku.com/articles/getting-started-with-nodejs
=== Heroku Addons ===
Addons have to be explicetely enabled on Heroku. Possible addons are
* WebSockets
* MongoDB
== Enabling Websockets ==
How to do that is described here: https://devcenter.heroku.com/articles/node-websockets
== Enabling MongoDb ==
MongoDB is a NoSQL DB.
To use a free Plan from [[https://www.mongohq.com/home|mongohq.com]]
- create an account
- add your data to the url mongodb://:@troup.mongohq.com:10078/buzznodejs
- use the library mongoskin as stated [[http://dllhell.net/2011/11/08/on-getting-started-with-node-js-mongodb-and-heroku-on-windows/|here]] npm install mongoskin
- Here is a short mongoskin syntax describtion: http://www.hacksparrow.com/mongoskin-tutorial-with-examples.html
// require mongoskin - the mongoDB library
var db = require('mongoskin').db('mongodb://:@troup.mongohq.com:10078/buzznodejs');
//insert some data
db.collection('bands').insert({ name: "guns n' roses", members: ['axl rose', 'slash', 'izzy stradlin', 'matt sorum', 'duff mckagan'], year: 1986 }, function (err, result) {
if (err) throw err;
if (result) console.log('added!');
});
// retrieve the collection named 'bands'
db.collection('bands').find().toArray(function (err, result) {
if (err) throw err;
console.log(result);
});
===== npx =====
https://www.freecodecamp.org/news/npm-vs-npx-whats-the-difference/
Sometimes you might want to take a look at a specific package and try out some commands. But you cannot do that without installing the dependencies in your local node_modules folder.
That’s where npx comes in.
npx @pactflow/swagger-mock-validator@latest