---
title: A JAVA Developer's Perspective on Node.js
description: A practical overview of Node.js in contrast with backend development using JAVA
image: https://blog.avenuecode.com/hubfs/Milena/nodejs.png
---

[AvenueCode.com](https://avenuecode.com) [News](https://avenuecode.com/news) [Contact](https://avenuecode.com/contact)

[![Avenue Code Snippets Logo](https://blog.avenuecode.com/hubfs/Avenue%20Code%20New%20Logos%20-%202023/AC-Snippets---Black.png)](https://blog.avenuecode.com/?hsLang=en-us) *menu*

- Technology
  
  [Cloud](https://blog.avenuecode.com/blog/topic/cloud?hsLang=en-us) [Delivery Infrastructure](https://blog.avenuecode.com/blog/topic/delivery-infrastructure?hsLang=en-us) [Web Experience](https://blog.avenuecode.com/blog/topic/web-experience?hsLang=en-us) [Agile Mindset](https://blog.avenuecode.com/blog/topic/agile-mindset?hsLang=en-us) [Quality First](https://blog.avenuecode.com/blog/topic/quality-first?hsLang=en-us)
  
  [Design](https://blog.avenuecode.com/blog/topic/design?hsLang=en-us) [Solution Architecture](https://blog.avenuecode.com/blog/topic/solution-architecture?hsLang=en-us) [Data & ML](https://blog.avenuecode.com/blog/topic/data-and-machine-learning?hsLang=en-us) [Mobile Experience](https://blog.avenuecode.com/blog/topic/mobile-experience?hsLang=en-us)
- [Whitepapers](https://blog.avenuecode.com/blog/topic/whitepapers?hsLang=en-us)
- [Spotlight](https://blog.avenuecode.com/blog/topic/spotlight?hsLang=en-us)
- [Extraordinary Women in Tech](https://blog.avenuecode.com/blog/topic/extraordinary-women-in-tech?hsLang=en-us)
- [Avenue Code Culture](https://blog.avenuecode.com/blog/topic/avenue-code-culture?hsLang=en-us)

- [Cloud](https://blog.avenuecode.com/blog/topic/cloud?hsLang=en-us)
- [Design](https://blog.avenuecode.com/blog/topic/design?hsLang=en-us)
- [Delivery Infrastructure](https://blog.avenuecode.com/blog/topic/delivery-infrastructure?hsLang=en-us)
- [Solution Architecture](https://blog.avenuecode.com/blog/topic/solution-architecture?hsLang=en-us)
- [Web Experience](https://blog.avenuecode.com/blog/topic/web-experience?hsLang=en-us)
- [Data & ML](https://blog.avenuecode.com/blog/topic/data-and-machine-learning?hsLang=en-us)
- [Agile Mindset](https://blog.avenuecode.com/blog/topic/agile-mindset?hsLang=en-us)
- [Mobile Experience](https://blog.avenuecode.com/blog/topic/mobile-experience?hsLang=en-us)
- [Quality First](https://blog.avenuecode.com/blog/topic/quality-first?hsLang=en-us)
- [Whitepapers](https://blog.avenuecode.com/blog/topic/whitepapers?hsLang=en-us)
- [Spotlight](https://blog.avenuecode.com/blog/topic/spotlight?hsLang=en-us)
- [Extraordinary Women in Tech](https://blog.avenuecode.com/blog/topic/extraordinary-women-in-tech?hsLang=en-us)
- [Avenue Code Culture](https://blog.avenuecode.com/blog/topic/avenue-code-culture?hsLang=en-us)

# [A JAVA Developer's Perspective on Node.js](https://blog.avenuecode.com/java-developer-exploring-nodejs)

- [Tweet](https://twitter.com/share)

*perm\_identity* [Milena Santos](https://blog.avenuecode.com/java-developer-exploring-nodejs/author/milena-santos?hsLang=en-us)

*schedule* 5/17/17 4:00 PM

> According to the latest StackOverflow [survey](http://stackoverflow.com/insights/survey/2017#technologies-and-occupations), Javascript is the top-ranked technology in terms of overall usage. Unsurprisingly, it's also top of the list for occupations, and with the advent of Node.js, has become increasingly in-demand.  

In this post, we'll be exploring the similarities of applications built in Node and JAVA. Rather than going into the specifics of each one, we'll focus on wrapping up the main components to get an app up and running. Ready to get our hands dirty? Let's go!

**Getting Started**

Before starting with Node.js, it's recommended that you have some basic familiarity with Javascript. However, if you're beginning to get accustomed to programming, don't give up! There are tons of tutorials like [this](http://javascript.info/) one to help familiarize you with the language, as well as infinite ways to practice. All you need is a text editor and a browser to get started!

If you'd like to try the examples presented here by yourself, you can:

- Download and Install [Node.js](http://nodejs.org/en/download/)
- Download and Install [MongoDB](http://www.mongodb.com/download-center)
- Choose your favorite [IDE](http://codecondo.com/best-ide-for-node-js)

 **Hands On**

**Dependency Management**

**NPM**

More than a build tool, the Node Package Manager (NPM) - which comes as a bonus when we install Node.js - centralizes open-source libraries and is also useful for multiple purposes such as initializing an app from scratch with "npm init", installing dependencies, packaging the app, running it, testing, and more. You can learn more about NPM in more detail [here](http://docs.npmjs.com/getting-started/what-is-npm).

The default file for assembling the project specs is the **package.json**, which can be as simple as the one below:

```
{  "name": "node-rest-ws",  "main": "server.js",  "dependencies": {    "express": "latest",    "body-parser": "~1.8.1",    "mongoose": "latest"  }}
```

The *"main"* defines the JS file that initializes the application, similarly to a Main class in a JAVA project (any class containing the void main(String\[\]) method), and there's no standard name for it.

Once we run "npm install" after defining our application dependencies, a folder named "node\_modules" is created on the project root folder, which is equivalent to the list of jars that are necessary for a JAVA app to compile.

If we add more dependencies after the first install, it won't create any  problems. We can simply specify what we want to install in order to be more precise (e.g. "npm install node-restful"), or simply trigger "npm install" again. 

**Maven**

As you might already know, Maven is the most popular build tool for managing JAVA project dependencies. There are a few others available as well, that are less common, such as the excellent [Gradle](http://gradle.org/).

Maven's central point is the **pom.xml**, which is commonly, if not always, saved on the project root folder as the package.json is for Node.

Below is the one used on our sample project:

```
<?xml version="1.0" encoding="UTF-8"?>
```

 **Database Configuration**

No hurdles here, with these lines in our main **server.js** file, we have MongoDB all set:

```
var mongoose = require('mongoose');mongoose.connect('mongodb://localhost/cms');
```

On the JAVA app the configuration is also pretty simple since we are using Spring Data MongoDB, so all we have to do is to define the following on the **application.properties**:

```
spring.data.mongodb.host=localhostspring.data.mongodb.port=27017spring.data.mongodb.database=cms
```

 **Backend Development**

See how the CRUD managed via RESTful services is structured on the Node application to the left? Not too differently from what we have on the JAVA correspondent to the right. 

| ![RESTful services on Node application.png](https://blog.avenuecode.com/hs-fs/hubfs/RESTful%20services%20on%20Node%20application.png?width=264&name=RESTful%20services%20on%20Node%20application.png) | ![JAVA correspondent.png](https://blog.avenuecode.com/hs-fs/hubfs/JAVA%20correspondent.png?width=228&name=JAVA%20correspondent.png) |
| --- | --- |

 See the similarities?

 **Model**

| ``` 'use strict';var mongoose = require('mongoose');var ProductSchema = new mongoose.Schema({ name: String, price: Number});module.exports = mongoose.model('Products', ProductSchema); ``` | ``` package com.avenue.blog.cms.model;//..imports@Documentpublic class Product { @Id private String id; private String name; private Double price; //..getters and setters} ``` |
| --- | --- |

**Controller**

| ``` 'use strict';var mongoose = require('mongoose'), Product = mongoose.model('Products');exports.list_all = function(req, res) { Product.find({}, function(err, product) { if (err) res.send(err); res.json(product); });};exports.save = function(req, res) { var product = new Product(req.body); product.save(function(err, product) { if (err) res.send(err); res.json(product); });};exports.read = function(req, res) { Product.findById(req.params.id, function(err, product) { if (err) res.send(err); res.json(product); });};exports.delete = function(req, res) { Product.remove({ _id: req.params.id }, function(err, product) { if (err) res.send(err); res.json({ message: 'Product deleted' }); });}; ``` | ``` package com.avenue.blog.cms.service;//..imports@Servicepublic class ProductService { @Autowired private ProductRepository repository; @Transactional(readOnly=true) public List<Product> listAll() { return repository.findAll(); } @Transactional(readOnly = true) public Product read(String id) { return repository.findOne(id); } @Transactional public Product create(Product p) { if (p != null) return repository.insert(p); return null; } @Transactional public Product update(Product p) { if (p != null && repository.exists(p.getId())) return repository.save(p); return null; } @Transactional public void delete(String id) { if (repository.exists(id)) repository.delete(id); }} ``` |
| --- | --- |

 **REST endpoints**

| ``` 'use strict';module.exports = function(app) { var product = require('../service/productService'); app.route('/api/products') .get(product.list_all) .post(product.save) .put(product.save); app.route('/api/products/:id') .get(product.read) .delete(product.delete);}; ``` | ``` package com.avenue.blog.cms.api;//..imports@RestController@RequestMapping("/api/products")public class ProductResource { @Autowired private ProductService service; @RequestMapping(method = RequestMethod.GET) public List<Product> listAll() { return service.listAll(); } @RequestMapping(method = RequestMethod.GET, value = "/{id}") public Product read(@PathVariable String id) { return service.read(id); } @RequestMapping(method = RequestMethod.POST) public Product create(@RequestBody Product p) { return service.create(p); } @RequestMapping(method = RequestMethod.PUT) public Product update(@RequestBody Product p) { return service.update(p); } @RequestMapping(method = RequestMethod.DELETE, value = "/{id}") public void delete(@PathVariable String id) { service.delete(id); }} ``` |
| --- | --- |

**Putting it All Together**

On our Node app we are linking the pieces starting from the **server.js**, defining the models, database, routes (which plug the controllers), and finally the application port, whereas on our JAVA app this is in place with annotations (remember that we're getting the advantage of all that Spring Boot can offer along with the most recent JDK). Before long, though, it's likely that we'll have similar support in Node.js. Check it out - attempts are already underway: take a look [here](http://www.npmjs.com/package/annotation).

Final **server.js** file:

```
var express = require('express'), bodyParser = require('body-parser'), Product = require('./src/model/productModel'), Category = require('./src/model/categoryModel');var app = express();app.use(bodyParser.json());var mongoose = require('mongoose');mongoose.Promise = global.Promise;mongoose.connect('mongodb://localhost/cms');var productRoutes = require('./src/routes/productRoutes');productRoutes(app);var categoryRoutes = require('./src/routes/categoryRoutes');categoryRoutes(app);app.listen(3000);console.log('Server running at port 3000');
```

 **Running the Application**

Now it's time to see if our efforts had any results. To test the exposed services, I've used [Postman](http://www.getpostman.com). See below.

*Creating a product*

![Using Postman to create a product.png](https://blog.avenuecode.com/hs-fs/hubfs/Using%20Postman%20to%20create%20a%20product.png?width=640&name=Using%20Postman%20to%20create%20a%20product.png)

*Updating a category*

![Using Postman to create a category.png](https://blog.avenuecode.com/hs-fs/hubfs/Using%20Postman%20to%20create%20a%20category.png?width=640&name=Using%20Postman%20to%20create%20a%20category.png)

*Retrieving all products*

![Using Postman to retrieve all products.png](https://blog.avenuecode.com/hs-fs/hubfs/Using%20Postman%20to%20retrieve%20all%20products.png?width=640&name=Using%20Postman%20to%20retrieve%20all%20products.png)

As we can see above, some of the services exposed by the Node application were successfully executed. To call the API's exposed by the JAVA app and test, all we need to do is change the port to 3001 since the same URI names were chosen and it's already up. 

**Frontend Development**

[Angular.js](https://angular.io) would be my natural choice for developing the UI for consuming both backend applications' REST APIs. Why? Simply because it is Javascript based and is a big success!

Working with JAVA, many of us have always had contact at one time or another with pure JSP/Servlet, Struts, JSF, or Spring MVC applications. These are still used for some newly created projects, and we'll always face them when working with legacy systems. But the world is changing. With the emphasis on Mobile First development, and the growing concern of building responsive apps that run well, multi-platform, JS-based client side apps are the way to go. 

Some of the many frameworks for building Javascript fullstack applications with Node and Angular include:

- [Meteor](https://www.meteor.com/)
- [MEAN.js](http://meanjs.org/)
- [Angular Full-Stack](https://angular-fullstack.github.io/)

**Conclusion**

Node.js really worth trying, even taking into consideration that's not recommended *yet* for any kind of app. Note: I say *yet *because it's evolving at such a fast pace that this argument will be defeated any day now. It's efficient for both fast development, and enabling lightweight apps to run with minimal effort. 

Recommended references besides the [official](https://nodejs.org) website:

- [Getting Started](https://dzone.com/refcardz/nodejs)
- [Good practices](https://blog.avenuecode.com/nodejs-anti-patterns?hsLang=en-us)
- [When to choose Node.js as your backend](https://www.netguru.co/blog/use-node-js-backend)

The code mentioned in this article is available for download [here](https://bitbucket.org/milenaps-ac/), have fun!

What are your thoughts regarding Node? Are you already using it on your projects? Please share with us! =)

---

[![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Blog/linkedin.png)](http://www.linkedin.com/in/milenaps)

### Author

# Milena Santos

 Milena Santos is a Full Stack Software Engineer at Avenue Code

---

### Related Posts

### What are CSS Custom Properties

[READ MORE](https://blog.avenuecode.com/what-are-css-custom-properties?hsLang=en-us)

### How to Build Your Own Facial Recognition Web App

[READ MORE](https://blog.avenuecode.com/how-to-build-your-own-facial-recognition-web-app?hsLang=en-us)

### 4 Ways to Make Your Angular App Sustainable and Scalable

[READ MORE](https://blog.avenuecode.com/8-design-tips-to-make-your-angular-app-sustainable-and-scalable?hsLang=en-us)

### How to Build a Custom Component in VueJS

[READ MORE](https://blog.avenuecode.com/how-to-build-a-custom-component-in-vuejs?hsLang=en-us)

### Leave a Comment!

### Avenue Code Social

[![Facebook Icon](https://blog.avenuecode.com/hubfs/Images/Blog/facebook.png?t=1486470796564)](https://www.facebook.com/avenuecode)

[![Twitter Icon](https://blog.avenuecode.com/hubfs/Images/Blog/twitter.png?t=1486470796842)](https://twitter.com/AvenueCode)

[![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Blog/linkedin.png?t=1486470796556)](https://www.linkedin.com/company/avenue-code)

### Newsletter

Want to stay on top of all tips and news from Avenue Code?

### Popular Snippets

![ac-logo-inverted.svg](https://blog.avenuecode.com/hubfs/Images/Logos/ac-logo-inverted.svg "ac-logo-inverted.svg")

### About Us

- [Who We Are](https://www.avenuecode.com/who-we-are)
- [What We Do](https://www.avenuecode.com/what-we-do)
- [Portfolio](https://www.avenuecode.com/portfolio)
- [Partners](https://www.avenuecode.com/partners)
- [News](https://www.avenuecode.com/news)
- [Events](https://www.avenuecode.com/events)
- [Blog](https://blog.avenuecode.com/)
- [Contact](https://www.avenuecode.com/contact)

### Our Offices

San Francisco

[+1 415 766 4178](tel:+553125161448) [ac.inquiries@avenuecode.com](mailto:brazil.info@avenuecode.com)

Belo Horizonte

[+55 31 2516 1448](tel:+553125161448) [brazil.info@avenuecode.com](mailto:brazil.info@avenuecode.com)

São Paulo

[+55 11 3205 3232](tel:+553125161448) [brazil.info@avenuecode.com](mailto:brazil.info@avenuecode.com)

### We're Hiring!

- [Belo Horizonte](https://www.avenuecode.com/who-we-are)
- [New York](https://www.avenuecode.com/what-we-do)
- [San Francisco](https://www.avenuecode.com/portfolio)
- [São Paulo](https://www.avenuecode.com/partners)

---

©2015 - 2017 Avenue Code

[![Facebook Icon](https://blog.avenuecode.com/hubfs/Images/Icons/facebook-2.png)](https://www.facebook.com/avenuecode) [![Twitter Icon](https://blog.avenuecode.com/hubfs/Images/Icons/twitter-2.png)](https://twitter.com/AvenueCode) [![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Icons/linkedin-2.png)](https://www.linkedin.com/company/avenue-code) [![Glassdoor Icon](https://blog.avenuecode.com/hubfs/Images/Icons/glassdoor-icon-1.png)](https://www.glassdoor.com/Overview/Working-at-Avenue-Code-EI_IE456173.11,22.htm) [![YouTube Icon](https://blog.avenuecode.com/hubfs/Images/Icons/youtube-2.png)](https://www.youtube.com/user/AvenueCodePlay)

/\*\* DISQUS SCRIPTS \*\*/ Please enable JavaScript to view the [comments powered by Disqus.](http://disqus.com/?ref_noscript)

© 2026 Avenue Code

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Milena Santos",
    "url" : "https://blog.avenuecode.com/author/milena-santos"
  },
  "datePublished" : "2017-05-17T19:00:00.000Z",
  "headline" : "A JAVA Developer's Perspective on Node.js",
  "image" : [ "https://blog.avenuecode.com/hubfs/Milena/nodejs.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.avenuecode.com/java-developer-exploring-nodejs",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.avenuecode.com/hubfs/Avenue%20Code%20New%20Logos%20-%202023/Avenue%20Code-primary%20versions_LOGO%20HORIZONTAL%20group%201-7.png"
    },
    "name" : "Avenue Code"
  }
}
```