Setup npm proxy in a corporate network

It’s painful to work behind a corporate network and everything does not work out of the box. Simple command like npm install would not work and here is how to work through the proxy:

Assuming you somehow get nodejs installed in your corporate laptop, open the .npmrc file which typical in the path for windows C:Users<your_user_id>.npmrc or mac Users/<your_user_id>/npmrc

Edit the file with this:


Try to run npm install again it should work now!

One more tip if you have some dependency hosted in your corperate internal Nexus npm repository, for example in the @ npmcorp scope, then run the below command to nominate the correct registry URL:

npm config set @npmcorp:registry https://your-company-nexus:80/nexus/content/repository/npm-internal

Then you should be able to overcome dependency not found errors. Try it out 🙂

Deploy Koa.js Application to AWS EC2 ubuntu instance

I am developing a Koa application, which is a new web framework designed by the team behind Express. Here is a step-by-step tutorial on how to deploy the koa.js application on your Amazon Web Service (AWS) ubuntu server.

Firstly, launch the ubuntu instance on AWS. Then you need to change the security group.

Otherwise if you hit the public domain in browser, it would stuck at “Connecting” state until timeout. And the site can’t be reached as shown as the screenshot below:

By default, the launch wizard group only has type ssh.

Click “Edit” button add HTTP port 80 and HTTPS port 443 inbound rule:

Secondly, ssh into your instance, install nodejs according to the official documentations:

$ curl -sL | sudo -E bash -
$ sudo apt-get install -y nodejs

Thirdly, we use Nginx as reverse proxy server:

$ sudo apt-get update
$ sudo apt-get install nginx

Open the configuration file and edit as below. Be careful not to miss the semicolon:

server { 
    listen 80 default_server;
listen [::]:80 default_server;
    root /var/www/yourApp;
    location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

Save the file and restart nginx service:

$ sudo systemctl restart nginx

Finally, clone your git repository to the path /var/www/yourApp, you will get a permission denied, so change ownership of the folder. You may replace the ubuntu part to ‘whoami’:

$ sudo chown -R ubuntu /var/www

Run your server, for example a simple app.js:

var koa = require('koa');
var app = koa();

// logger

app.use(function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
console.log('%s %s - %s', this.method, this.url, ms);

// response

app.use(function *(){
this.body = 'Hello World';


Start the server:

$ node app.js

Open your browser and hit your public domain:

Done. Leave a comment below if you have any questions 🙂