debug nodejs in chrome

The new chrome ships with the about:inspect and a dedicated debugger for nodejs which is super cool! At least we do not have to rely solely on console.log() magic. To do that, run script with an additional flag: node –inspect myServer.js This should fire up the app and then go to a new tab and enter about:inspect. Then…

nodejs eventloop 和libuv

NodeJS and Chrome eventloop Node.js and Chrome do not use the same event loop implementation. Chrome/Chromium uses libevent, while node.js uses libuv. Node’s API provides a kind of asynchronous no-op, setImmediate. For that function, the “some operation” I’ve mention above is “do nothing”, after which an item is immediately added to the end of the…

require exports module in nodejs/requirejs/commonjs

What is a Module A module encapsulates related code into a single unit of code. When creating a module, this can be interpreted as moving all related functions into a file. Let’s illustrate this point with an example involving an application built with Node.js. Imagine that we created a file called greetings.js and it contains…

How bower works.

When I first looked into Bower, I wasn’t exactly sure how it fit in: it wasn’t just a JavaScript package manager, like Jam, and it wasn’t a module loader, like RequireJS. It calls itself a browser package manager, but what exactly does this mean? How’s that different from a JavaScript package manager? The main difference…

missing jwt options in token using nodejs jsonwebtoken

I am using jsonwebtoken to handle the token generation and verification on the server side. The way I did it is once user auth successfully, I sign the ‘user’ object directly to generate the token like this: var token = jwt.sign(user, secret.secretToken, {expiresInMinutes: 60, issuer: ‘cccg’, algorithm:’HS384′}); I found my token never expires. After debugging(you can…

deploy nodejs angularjs mongodb expressjs application to openshift

In my previous post, I described how to upload file using nodejs and angularjs. Now we are to deploy this MEAN stack app to openshift which is a very good cloud service provider offering 3 application deployment for free. You can even deploy Java web application to it using Tomcat/Mysql, part of which i mentioned…

nodejs log to file for multiple modules

There are several projects provide the ability to log to file for nodejs like log4js, winston etc. I picked winston for no specific reason. init setup is pretty simple, just follow what is written in Github. To make it be able to be shared by multiple modules, we need some tweaks. First we need a…

debug nodejs with nodemon and intellij

Noticed that if I run nodemon within intellij, I would not be able to debug any more inside intellij. Not sure what reason it is. If just run the nodejs, no problem. However once I add the ‘/usr/local/bin/nodemon’ into the Node parameters of the run config, the breakpoint would not work. solution To solve this…

authentication angular nodejs with JWT

Why use it? Here are some advantages of choosing JWT: Standard: JWT is becoming a standard, and there a multiple libraries for a lot of languages (Ruby, Java, Python, Node, Backbone). So the integration with your language or technology should be pretty easy. Cross-domain / CORS: Since the information is transmitted using an HTTP header, you are…

build rest api with node and express js

1. in the app js we need   2. To share the mongo db connection we can have the db info in a js file: 3. To share the model schema, we can put the content in a js file: 4. then in the rest implementation js module : DONE. To test them , remember…

set up node js

Was playing around with node today, some notes for setting up. To install node, just go to the nodejs site and download. To run sample from the node site, create the something like yourapp.js file with the content they provide, open cmd or your terminal, navigate to the folder containing the js file. and run…