Node.js

When I was researching for my BeagleBone Black I saw in material two things I had read about earlier: Cloud9 IDE on node.js.

I wanted to test node.js. Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model. The idea of using JavaScipt on server end is not new, but node.js seems to have good traction compared to older alternatives. Node.js is often seen as a great tool for writing simple and efficient application servers with server-side JavaScript. So it should be worth to try to know what it is.

It was pretty easy to get started with node.js from the Cloud9 IDE basic demo application and looking for more information on-line how to code with node.js. After some playing I got feeling that this node.js could make sense for some applications.

Here is one of my first node.js test programs. It gives out a web page that prints the requested URL and “Hello World”.


// reference the http module so we can create a webserver
var http = require("http");
var url = require("url");

// create a server
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
var pathname = url.parse(request.url).pathname;
// on every request, we'll output 'Hello world'
response.write("Test request:" + pathname + "nr");
response.end("Hello world from Cloud9!");
}).listen(process.env.PORT, process.env.IP);

// Note: when spawning a server on Cloud9 IDE,
// listen on the process.env.PORT and process.env.IP environment variables

More advanced node.js systems often use in-memory data structures. Persistent state for Node.js application servers article mentions that the problem with in-memory data structures is that they are lost when restarting the Node.js application. During development this happens all the time. The article gives some tips how to solve this problem.

22 Comments

  1. Runnable « Tomi Engdahl’s ePanorama blog says:

    [...] on the service itself, and it spans several programming platforms, including PHP, JavaScript and Node.js, and Ruby on Rails. The service is still in the beta testing stage, but us well worth to take a [...]

    Reply
  2. Tomi Engdahl says:

    Microsoft Adds Node.js Support To Visual Studio
    http://developers.slashdot.org/story/13/11/21/1757203/microsoft-adds-nodejs-support-to-visual-studio

    “Coming from the team that had previously brought you Python Tools for Visual Studio, Microsoft has announced Node.js Tools for Visual Studio, with the release of the first public alpha. NTVS is the official extension for Visual Studio that adds support for Node.js, including editing with Intellisense, debugging, profiling, and the ability to deploy Node.js websites to Windows Azure.”

    Reply
  3. Tomi Engdahl says:

    Open-source blogging platform Ghost begins rolling out its fully-hosted service
    http://thenextweb.com/media/2013/12/16/open-source-blogging-platform-ghost/#!p4JAa

    Ghost, the Node.js-based open-source blogging platform that launched to the public in October following a successful Kickstarter campaign, is rolling out the fully-hosted version of the platform.

    In an email sent out to users this week, the team says that they’ve been beta testing the hosted version with “several thousand” people over the past month, and it’s now ready for launch. Though it isn’t yet switched on for everybody.

    Founded by former WordPress UI Group Deputy Head John O’Nolan, and WordPress developer Hannah Wolfe, Ghost is looking to make a name for itself by focusing on pure publishing and blogging. Think WordPress…but simplified.

    Reply
  4. Tomi Engdahl says:

    Web Interface for the FRAM LaunchPad
    http://hackaday.com/2014/04/05/web-interface-for-the-fram-launchpad/

    The Internet of Things is here in full force. The first step when adding to the Internet of Things is obvious, adding a web interface to your project.

    The LaunchPad simply interfaces with the computer using USB and Python, and the computer hosts the webpage and updates it in real time using Node.js.

    Reply
  5. Tomi Engdahl says:

    Node.js has now more packages available than Java or Ruby (or anything else) and is that number is growing quickly.

    Source: http://www.modulecounts.com/

    Reply
  6. Tomi Engdahl says:

    Node.js v4.0.0 Released
    http://news.slashdot.org/story/15/09/08/1936221/nodejs-v400-released?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Slashdot%2Fslashdot%2Fto+%28%28Title%29Slashdot+%28rdf%29%29

    The first merge of the popular Node.js and io.js repositories has been released! From the announcement: “The collaborators of the Node.js project and the members of the Node.js Foundation are proud to offer v4.0.0 for general release.

    Node v4.0.0 (Stable)
    https://nodejs.org/en/blog/release/v4.0.0/

    Node.js v4.0.0 contains V8 v4.5, the same version of V8 shipping with the Chrome web browser today.

    Over the past year thanks to donations from companies such as Rackspace, DigitalOcean, Scaleway, miniNodes, Voxer, Joyent, CloudFlare, ARM Holdings, and individuals from the community, we’ve built an amazing test cluster that includes an impressive line-up of Linux variants, OS X, Windows, FreeBSD and SmartOS. New to Node.js, we also have first-class support for ARM processors. Our test suite must be continually passing on ARMv6, ARMv7 and the new 64-bit ARMv8 processors. So Node.js is officially ready for use by hobbyists and ARM server users alike.

    Node.js v4 also brings a plan for long-term support (LTS) and a regular release cycle. Release versioning now follows SemVer, so expect increments of both minor and patch version over the coming weeks as we fix bugs and add features. What we won’t be doing within the v4.x branch is adding breaking changes.

    Reply
  7. Tomi Engdahl says:

    Node.js Version Chaos Management
    http://www.linuxjournal.com/content/nodejs-version-chaos-management

    I’m just starting out in the world of development, and many of the projects I’m interested in exploring are written in Node.js. If you’re an old hand at such things, you already know that which version of Node you use on a particular application is vitally important. (This is actually one of the reasons Docker is so amazingly amazing when it comes to deploying Node apps, but I digress.)

    For folks like me, the version issue can be confusing and frustrating. Thankfully, I ran across a simple tool with a simple name: n. Once you have Node.js installed on your system, using n, it’s possible to download and make active a very specific version of the program, so your specific application works properly.

    There are instructions on the Github page: https://github.com/tj/n.

    Reply
  8. Tomi Engdahl says:

    Microsoft requests ChakraCore support in main Node.js repository
    Only on Windows for now, but cross-platform is promised
    http://www.theregister.co.uk/2016/01/20/microsoft_requests_chakracore_support_in_main_nodejs_repository/

    Microsoft has submitted a pull request that enables Node.js to run with the ChakraCore JavaScript engine, as an optional alternative to the Google-developed V8 engine.

    Chakra is the JavaScript engine developed for Edge, Microsoft’s Windows 10 web browser. In December 2015, the company announced that the key components of Chakra would be open source, and ChakraCore is now on GitHub.

    Unlike Edge, ChakraCore runs on Windows 7 SP1 or above. It is currently Windows-only, though a cross-platform implementation is on the roadmap, with the initial goal being support for 64-bit Ubuntu for the interpreter and runtime only (no just-in-time compiler). Microsoft also plans to add full support for ECMAScript 2015, also known as ECMAScript 6.

    Reply
  9. Tomi Engdahl says:

    Agdubs / The npm Blog:
    npm no longer allowing developers to automatically unpublish packages over 24 hours old — changes to npm’s unpublish policy — One of Node.js’ core strengths is the community’s trust in npm’s registry. As it’s grown, the registry has filled with packages that are more and more interconnected.

    changes to npm’s unpublish policy
    http://blog.npmjs.org/post/141905368000/changes-to-npms-unpublish-policy

    One of Node.js’ core strengths is the community’s trust in npm’s registry. As it’s grown, the registry has filled with packages that are more and more interconnected.

    A byproduct of being so interdependent is that a single actor can wreak significant havoc across the ecosystem. If a publisher unpublishes a package that others depend upon, this breaks every downstream project that depends upon it, possibly thousands of projects.

    Last Tuesday’s events revealed that this danger isn’t just hypothetical, and it’s one for which we already should have been prepared. It’s our mission to help the community succeed, and by failing to protect the community, we didn’t uphold that mission.

    We’re sorry.

    Reply
  10. Tomi Engdahl says:

    Node.js Version 6 Released With LTS
    https://news.slashdot.org/story/16/04/26/1941203/nodejs-version-6-released-with-lts

    The JavaScript runtime Node.js has reached version 6.0, and unlike version 5.0 this version will receive Long Term Support (LTS). LTS is meant to provide the release with long-term stability, reliability, performance and security. The LTS will begin in October. The current LTS release will go into maintenance mode and will only receive bug, security and documentation updates. Version 5.0 of Node.js will continue to be maintained for a few more months. The latest version features improved module loading, 96% of ECMAScript 2015 features, as well as reliability and security enhancements.

    Node.js version 6 released
    http://sdtimes.com/node-js-version-6-released/

    The JavaScript runtime Node.js hit version 6 today with performance advancements as well as reliability and security enhancements. This version, unlike version 5.0, is intended to be a long-term support release in order to provide front-end, back-end, Web and IoT developers with a consistent and high-quality solution.

    “This release is committed to Long Term Support [LTS], which allows predictable long-term stability, reliability, performance and security to the growing number of enterprise users that are adopting Node.js as a key technology in their infrastructure,” said Mikeal Rogers, community manager for the Node.js Foundation.

    According to the Node.js Foundation, the highlight of this release is in the module loading performance improvements. Module loading is expected to be 4x faster than the current LTS release (version 4) and will help developers accelerate their application development release cycles. Other performance updates include V8 JavaScript engine 5.0 with improved ECMAScript 2015 support. The previous release accounted for 56% of ES6 features, and this release is meant to include 93% of its features, such as default and rest parameters, destructuring, class, and super keywords.

    Reply
  11. Tomi Engdahl says:

    World’s Fastest Growing Open Source Platform Pushes Out New Release
    https://nodejs.org/en/blog/announcements/v6-release/?release

    New “Current” version line focuses on performance improvements, increased reliability and better security for its 3.5 million users

    SAN FRANCISCO, April, 26, 2016 — The Node.js Foundation, a community-led and industry-backed consortium to advance the development of the Node.js platform, today announced the release of Node.js version 6 (Node.js v6). This release provides major performance improvements, increased reliability and better security.

    With over 3.5 million users and an annual growth rate of 100 percent, Node.js is emerging as a universal platform used for web applications, IoT, mobile, enterprise application development, and microservice architectures. The technology is ubiquitous across numerous industries, from startups to Fortune 500 companies, and is the only unified platform that full stack JavaScript developers can use for front end, back end, mobile and IoT projects.

    Node v5.0.0 (Current)
    https://nodejs.org/en/blog/release/v5.0.0/

    Reply
  12. Tomi Engdahl says:

    Ask Slashdot: Have You Migrated To Node.js?
    https://ask.slashdot.org/story/16/05/22/1611230/ask-slashdot-have-you-migrated-to-nodejs

    Have you moved from LAMP (PHP) to Node.js for custom product development and if so, what’s your advice? What downsides of JS on the server and in Node.js have a real-world effect? Is callback hell really a thing?

    Condensing Qbertino’s original submission: he wants to be able to quickly deliver “pretty, working, and half-way reliable products that make us money” — and to build a durable pipeline.

    Comments:
    JavaScript is a horrible language, as you can see [opentechschool.org]. But PHP is also a horrible language. If you are writing a lot of JS for the client side, then node.js has the advantage that you only need to learn one horrible language.

    See, I don’t get all the hate towards JavaScript. From what I’ve seen, it’s a perfectly usable language except for the lack of true classes, and even that flaw can be fairly easily worked around if you’re a C programmer who did OO back before it was cool (function pointers).

    What makes client-side JavaScript a nightmare is not the language, but rather the DOM, which is kind of a pain in any language. The biggest difference is that in other languages, most developers never have to deal with the DOM….

    No.

    We don’t like Node because Javascript is eccentric (read: benignly insane) in too many ways. If there was an alternative, that would be adopted in a heartbeat. Something with sensible types and type casting at least, preferably with a better, non-prototype object model.

    I come from a strong C++/Java background and was drug into the Node/JS world kicking and screaming. It’s still not my platform of choice but at least I don’t despise it anymore. A few things:

    1. Don’t try to write PHP (or C++/Java/etc) with Javascript. You see a lot of people try to force Javascript into their way of programming and that’s where a lot of the callback hell comes from. It’s an event driven environment, just repeat that over and over.

    2. Take the time to familiarize yourself with ES6/Promises/Rx before you start. Promises vs. Rx is almost a religious discussion but when you get down to it, both do the job. This helps a lot with callback hell.

    3. After you’ve chanted it’s an event driven environment often enough, start chanting everything is a stream [slides.com].

    3. Use eslint religiously. This will find a lot of the mistakes new programmers make, especially ones coming from other languages.

    Reply
  13. Tomi Engdahl says:

    Node.js Versions Used in Commercial Projects in 2017
    https://semaphoreci.com/blog/2017/11/22/nodejs-versions-used-in-commercial-projects-in-2017.html

    The Node community is constantly expanding and enterprises are adding it to their stacks, because they can use the same language throughout the entire stack. This year, the Node.js Foundation released the results of a survey which identified how and on which projects people use it. One thing they haven’t covered are the versions of Node.js used in projects, which we’ll do in this post.

    Reply
  14. Tomi Engdahl says:

    10 Things I Regret About Node.js – Ryan Dahl – JSConf EU 2018
    https://m.youtube.com/watch?feature=youtu.be&v=M3BM9TB-8yA

    Reply
  15. Tomi Engdahl says:

    Build an interactive CLI with Node.js
    https://opensource.com/article/18/7/node-js-interactive-cli?sc_cid=7016000000127ECAAY

    Use Node.js to build a command-line interface that creates a file based on your needs.

    Reply
  16. Tomi Engdahl says:

    10 Things I Regret About Node.js – Ryan Dahl – JSConf EU
    https://www.youtube.com/watch?v=M3BM9TB-8yA

    https://en.wikipedia.org/wiki/Deno_(software)
    Deno is a runtime for JavaScript and TypeScript that is based on the V8 JavaScript engine and the Rust programming language. It was created by Ryan Dahl, original creator of Node.js, and is focused on productivity.[

    Reply
  17. Tomi Engdahl says:

    NodeJS 16 is officially released
    https://sudosecurity.org/nodejs-16-is-officially-released/

    NodeJS 16 was just released this week – it has added additional stable APIs to the popular JavaScript Runtime and even supports Apple Silicon. This release is the first to ship with binaries for Apple Silicon – they do provide separate tarballs for the Intel and ARM architectures.

    Reply
  18. Tomi Engdahl says:

    Build a Web Scraper (super simple!)
    https://www.youtube.com/watch?v=-3lqUHeZs_0

    In this video I show you how to build a Web Scrapper in a super simple beginner friendly way using Node.js.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

*

*