17 private links
- Make XMLHttpRequests from the browser
- Make http requests from node.js
- Supports the Promise API
- Intercept request and response
- Transform request and response data
- Cancel requests
- Automatic transforms for JSON data
- Client side support for protecting against XSRF
It is now available with the latest PM2 version:
{
apps : [{
name : 'API',
script : 'api.js',
interpreter : 'node@6.9.1'
}]
}
https://github.com/Unitech/pm2/blob/master/test/fixtures/nvm-node-version/ecosystem.json#L12
You can use environment variable.
For example:
1) NODE_PORT=3002 pm2 start -I 0 app.js
2) Read value in app:
console.log(process.env.NODE_PORT);
Or, if you are build express app:
1) PORT=3002 pm2 start -I 0 ./bin/www
2) Express load PORT automatically at start application.
Generate massive amounts of fake data in the browser and node.js
This is a complete and feature rich Redis client for node.js. It supports all Redis commands and focuses on high performance.
Install with:
npm install redis
As others have recommended in comments, it looks like the canonical way to test Express controllers is through supertest.
An example test might look like this:
describe('GET /users', function(){
it('respond with json', function(done){
request(app)
.get('/users')
.set('Accept', 'application/json')
.expect(200)
.end(function(err, res){
if (err) return done(err);
done()
});
})
});
Upside: you can test your entire stack in one go.
Downside: it feels and acts a bit like integration testing.
A Test-Anything-Protocol library for Node.js
One of the things that really got me on board with NodeJS was the idea that I didn’t need a host container for it. Building a web app just means including a library that listens for HTTP requests on a port and respond. No more Apache! One less thing to worry about that isn’t my app!
And then it starts getting complicated.
For a start, port 80 is a privileged port, so when you try to launch the app to test or develop on your own machine you need to do so with sudo. That’s a little annoying, but you could default to port 80 & allow an override. But now you are adding more code to workaround it.
And what about SSL? If you are going to use SSL in production (and you should) then your code is going to have to know about that too and read the certs and set that up. And that’s even more annoying for development, anyone working on your code is going to have to create their own certs just to launch your app. Unless you code in more workarounds.
So that’s a suddenly a lot of code you are maintaining which might create its own problems.
The alternative … use a webserver as a proxy for your app in production. It doesn’t have to be Apache, you could use Nginx for example. I use Apache because I’m reasonably familiar with it.
Most of the JS ecosystem JSON validators are too complicated. I like the simplicity and this one is perfect
A curated directory of boilerplates to help you start your projects!
A good option is Node-supervisor and Node.js Restart on File Change is good article on how to use it, typically:
npm install supervisor -g
and after migrating to the root of your application use the following
supervisor app.js
Node.js as a running service is becoming more and more popular these days. One of the issues many developers face is how to ensure their node.js service starts automatically, and more importantly how to keep it running should it crash. Previously one had to install modules such as forever, and then create some autostart script to start the daemon when the server booted.
Most Linux systems have recently switched to using systemd, which makes this process a lot simpler and more efficient, and means that we do not need forever any more.
When you run Express apps for production, it is helpful to use a process manager to achieve the following tasks:
- Restart the app automatically if it crashes.
- Gain insights into runtime performance and resource consumption.
- Modify settings dynamically to improve performance.
- Control clustering.
A process manager is somewhat like an application server: it’s a “container” for applications that facilitates deployment, provides high availability, and enables you to manage the application at runtime.
The most popular process managers for Express and other Node.js applications are as follows:
- StrongLoop Process Manager
- PM2
- Forever
- SystemD
Using any of these three tools can be very helpful, however StrongLoop Process Manager is the only tool that provides a comprehensive runtime and deployment solution that addresses the entire Node.js application life cycle, with tooling for every step before and after production, in a unified interface.
Here’s a brief look at each of these tools. For a detailed comparison, see http://strong-pm.io/compare/.