background preloader

Node JS

Facebook Twitter

Keeping Your NodeJS Web App Running on Production Linux | Binarymist. All the following offerings that I’ve evaluated target different scenarios. I’ve listed the pros and cons for each of them and where I think they fit into a potential solution to monitor your web applications (I’m leaning toward NodeJS) and make sure they keep running. I’ve listed the goals I was looking to satisfy. For me I have to have a good knowledge of the landscape before I commit to a decision and stand behind it. I like to know I’ve made the best decision based on all the facts that are publicly available. I looked at quite a few more than what I’ve detailed below, but the following candidates I felt were worth spending some time on. Keep in mind, that everyone’s requirements will be different, so rather than tell you which to use because I don’t know your situation, I’ve listed the attributes (positive, negative and neutral) that I think are worth considering when making this choice.

Evaluation criterion Who is the creator. Goals Sysvinit, Upstart, systemd & Runit systemd forever. Implement Access Control in Node.js — Security and Node.js — Medium. Most web applications rely on some sort of access control to keep users from accessing information not meant for them. If authentication is a lock on the main door of the hotel, then access control is the individual access card they give to each user for accessing their room. We have spent quite a few posts talking about various theories about security mechanisms for a web application. In this blog post we will not stop at theory, but will take a more hands on approach to helping the community secure the web by building a RBAC module from the ground up that we can use to check our user's privileges.

We'll begin by going over the theory of access control then proceed with incrementally building it. For a more thorough overview of authentication, access control methods and other Node.js security topics I recommend you read my book Secure Your Node.js Web Application: Keep Attackers Out and Users Happy So without further distractions let's get started. Relearn Access Control Details of RBAC. How to not break the internet with this one weird trick. How to not break the internet with this one weird trick If you write JavaScript tools or libraries, you should bundle your code before publishing.

A few hours ago, Azer Koçulu ‘liberated’ his collection of modules from npm following a trademark dispute. One of them — an 11-line utility for putting zeroes in front of strings — was heavily depended on by other modules, including Babel, which is heavily depended on by the entire internet. And so the internet broke. People confirmed their biases: People panicked: And people got angry: Everyone involved here has my sympathy. Bundle your code, even if it’s not for the browser Just to recap: left-pad was unpublishedBabel uses fixed versions of its dependencies, one of which (transitively) was left-padWhen you install Babel, you also install all its dependencies (and their dependencies)Therefore all old versions of Babel were hosed (until left-pad was un-unpublished)People blame Azer The key item here is number 3.

You waste less disk space I’m sold! Незащищённость NPM к атакам по внедрению вредоносных модулей-червей. Инцидент с нарушением работы многих известных проектов после удаления модуля из NPM-репозитория привёл к обсуждению незащищённости NPM от атак, инициированных со стороны разработчиков модулей. В том числе раскрыты данные о незащищённости инфраструктуры NPM к атаке по внедрению в репозиторий самораспространяющихся вредоносных модулей. Совершению атаки способствуют несколько факторов: Использование семантического версионирования (SemVer), по умолчанию не привязывающего приложение к конкретным версиям модулей, что позволяет инициировать установку обновления модуля через выпуск его новой версии; Применение постоянного кэширования параметров аутентификации в NPM - после входа с машины разработчика можно выполнять любые действия от его имени, пока разработчик вручную не отсоединится от репозитория. Подобный подход мешает разработчику контролировать свою активность в репозитории, что может быть использовано для скрытой публикации обновлений с его компьютера.

Async Fragments: Rediscovering Progressive HTML Rendering with Marko | eBay Tech Blog. At eBay, we take site speed very seriously and are always looking for ways to allow developers to create faster-loading web apps. This involves fully understanding and controlling how web pages are delivered to web browsers. Progressive HTML rendering is a relatively old technique that can be used to improve the performance of websites, but it has been lost in a whole new class of web applications. The idea is simple: give the web browser a head start in downloading and rendering the page by flushing out early and multiple times. Browsers have always had the helpful feature of parsing and responding to the HTML as it is being streamed down from the server (even before the response is ended).

This feature allows the HTML and external resources to be downloaded earlier, and for parts of the page to be rendered earlier. As a result, both the actual load time and the perceived load time improve. Background Without progressive HTML rendering Flushing the head early Multiple flushes Summary. Your First GraphQL Server. So, today we’re going to write a small GraphQL server. I’m not going to try to persuade you to drop everything and adopt GraphQL — but if you’re curious about what this stuff looks like today and how it works, read on. Setup an HTTP Server We need a server to receive our GraphQL queries. There’s nothing in the GraphQL spec that demands we do this over HTTP, but since the GraphQL reference implementation is in JavaScript, it’s expedient to roll a quick HTTP server with Express. $ mkdir graphql-intro && cd .

/graphql-intro$ npm install express --save$ npm install babel --save$ touch . This creates a folder for our project (graphql-intro), and installs Express and Babel as dependencies. Finally, let’s write some code: To run our server, execute: $ node index.jsGraphQL listening at To test that things are working: $ curl -XPOST Create a GraphQL Schema Now that we have a server we can talk to, it’s time to “add some GraphQL”. Connect the Schema.

Hidemyass. Icodeforlove/node-requester. Production-Quality Node.js Web Apps : Part I, The Basics - caines.ca. I’ve been working on production-quality node.js web applications for a couple of years now, and I thought it’d be worth writing down some of the more interesting tricks that I’ve learned along the way. I’m mostly going to talk about maintaining a low-defect rate and high availability, rather than get into the details about scaling that are covered in a lot of other places. In particular, I’ll be talking about load-balancing, process management, logging, and metrics, and the how’s and why’s of each. Balance the Load I’m going to assume that you’re already load-balancing on a given server with cluster or some higher level abstraction ( I use cluster-master) as well as between servers with a load-balancer like ha-proxy.

Performance considerations aside, your service will have much better availability, quality, and uptime if you’ve got multiple processes running on multiple machines. Gracefully Deploy Run as a Service Log to Standard Output pipe it, don’t write it rotating the logs Metrics. What’s New in Node.js v0.12: Cluster Round-Robin Load Balancing. Editor’s Note Welcome to the first installment of what will likely be a seven or eight part series of blog posts authored by Node core commiters, Ben Noordhuis and Bert Belder, covering the new features currently slated for inclusion in v0.12 of Node.js.

In this first post, Ben looks at the new round-robin clustering algorithm. Recap: Node’s built-in cluster module In the days of yore, an oft-lamented limitation of Node.js was its intrinsically single-threaded model. No matter how many cores your machine had, Node.js would utilize only one (with the caveat that some operations are offloaded to a thread pool. For most applications that’s just a blip on the total amount of CPU time though, so it doesn’t really help with better utilizing the available processing power.)

That is why Node.js v0.8 saw the addition of the new built-in ‘cluster’ module. The application need not know it’s running in a clustered environment. …at least, in theory. So far, so good. Reality check A Note on Windows. BDD with MEAN – The Server Part 1 | attackOfZach. As with any new endeavor, it pays to spend some time trying various solutions out and sometimes failing miserably. This is especially true for us progressive nerds who like to live on the bleeding edge without things like Stack Overflow to constantly save our ass. What I’d like to do is to help you avoid going through the pain of figuring out what works and what doesn’t. As I mentioned in my previous post, I already have a project that serves as a working example of if you wish to jump straight into the code: .

All of the gists used in this post were pulled from that project. The first step on our journey to effective BDD testing with the MEAN stack will be to start wiring up the various tools we’ll need to use to get a working environment. Afterwards, we’ll build out a helper to manage our test environment and fixtures. Let’s start by reviewing our toolbox: Our Tool Box GruntGrunt is used for general task running, . Folder structure The Gruntfile Summary. Top 10 Mistakes Node.js Developers Make. Node.js in Flames. We’ve been busy building our next-generation Netflix.com web application using Node.js. You can learn more about our approach from the presentation we delivered at NodeConf.eu a few months ago.

Today, I want to share some recent learnings from performance tuning this new application stack. We were first clued in to a possible issue when we noticed that request latencies to our Node.js application would increase progressively with time. The app was also burning CPU more than expected, and closely correlated to the higher latency. While using rolling reboots as a temporary workaround, we raced to find the root cause using new performance analysis tools and techniques in our Linux EC2 environment. Flames Rising We noticed that request latencies to our Node.js application would increase progressively with time. This graph plots request latency in ms for each region against time. Dousing the Fire Something was taking an additional 60 ms to service the request. [a, b, c, c, c, c, d, e, f, g, h] Node OS. What Makes Node.js Faster Than Java?

Every few weeks someone posts a Java vs Node benchmark, like PayPal’s or Joey Whelan’s. As one of maintainers of Node core and contributors to many npm modules, StrongLoop is happy to see Node winning lately. Everyone knows benchmarks are a specific measurement and don’t account for all cases. Sometimes Java is faster. Sometimes Node is. Certainly what and how you measure matters a lot. High concurrency matters But there’s one thing we can all agree on: At high levels of concurrency (thousands of connections) your server needs to go to asynchronous non-blocking. While Java or Node or something else may win a benchmark, no server has the non-blocking ecosystem of Node.js today.

Big companies, committed vendors and engaged community We’re going to help keep maturing Node and the ecosystem of tools and libraries as well. Use StrongOps to Monitor Node Apps Ready to start monitoring event loops, manage Node clusters and chase down memory leaks? What’s next? Full Stack JavaScript: Backbone, Node, Express & More. The Story So, you and your co-founder have this great idea for a business, right? You’ve been adding features in your mind. Frequently, you ask potential customers for their opinions, and they all love it. Ok, so people want it.

There’s even some money to be made. And the only reason they can’t have it is because you haven’t implemented it—yet. So finally, you sit down one day and say, “Let’s do it!” “Done! “Ok, let’s create the site”, you say. And then, you realize the truth: you need to choose a programing language; you need to choose a (modern) platform; you need to choose some (modern) frameworks; you need to configure (and purchase) storage, databases, and hosting providers; you need an admin interface; you need a permissions system; you need a content manager.

You want to be lean, you want to be agile. You have tens upon tens of architectural decisions to make. “I’m overwhelmed,” you say, as you feel overwhelmed. Your proof of concept slowly withers and dies. The Proposal About the author. Why Use Node.js? A Comprehensive Tutorial with Examples. Introduction JavaScript’s rising popularity has brought with it a lot of changes, and the face of web development today is dramatically different. The things that we can do on the web nowadays with JavaScript running on the server, as well as in the browser, were hard to imagine just several years ago, or were encapsulated within sandboxed environments like Flash or Java Applets. Before digging into Node.js, you might want to read up on the benefits of using JavaScript across the stack which unifies the language and data format (JSON), allowing you to optimally reuse developer resources.

As this is more a benefit of JavaScript than Node.js specifically, we won’t discuss it much here. But it’s a key advantage to incorporating Node in your stack. As Wikipedia states: “Node.js is a packaged compilation of Google’s V8 JavaScript engine, the libuv platform abstraction layer, and a core library, which is itself primarily written in JavaScript.” How Does It Work? That’s a mouthful. Pros: Cons: 10 steps to nodejs nirvana in production | Thruput | Garbage In, Garbage Out. We have been using node.js in production environments since a few years now, back when it was still in 0.4. We have used node for ecommerce, for ad-serving, as an API server and just about everything else, short of calculating the nth fibonacci number (we use GO for that sort of stuff, no kidding). When you run stuff in production, and at scale, there are lessons to be learned and insights to be gleaned, sometimes the hard way.

This is a compilation of certain learnings that work for us, listed here in the hope that someone may find it useful. YMMV. For the impatient, here is the tl;dr Don’t reinvent the wheel, follow the unix way of doing things. As with any high availability system, you need to make sure that your node process is up all the time, and it starts at boot time. Upstart is not available everywhere, but our production environments has always been Ubuntu, where it is available by default. Using upstart is fairly simple, just place the config file in /etc/init. Log rotation. Code.tutsplus. Koa.js is an expressive next-generation web framework written for Node.js by the people behind the Express and Connect frameworks. Koa.js leverages generators, which are a bleeding edge feature of JavaScript, and have not yet been made into stable versions of Node.js. Koa aims to use generators to save developers from the spaghetti of callbacks, making it less error-prone and thus more manageable.

With just 550 lines of code, Koa is an extremely light framework. Even after that, Koa packs in an elegant suite of methods such as content-negotiation, redirections, proxy support etc., giving you ease and speed of development along with the granular control over your node application. Now before we begin, you will need to have at least Node version 0.11.x or greater. You can install the latest version of Node using the N module : You can also use other community modules like nvm or build it from source. For example, to run app.js, enter in the following command: Very good! Example: sum.next(5); Node.js in Production. Fully Loaded Node – A Node.JS Holiday Season, part 2. Lloyd/node-compute-cluster. Why you should use Node.js for CPU-bound tasks - Neil Kandalgaonkar. JXcore – A Node.JS Distribution with Multi-threading. Dandean/express-form. Building A Node.JS Server That Won’t Melt – A Node.JS Holiday Season, part 5.

Learn

Modules. Frameworks. Node.js. Npm. Полезные инструменты, туториалы и ресурсы. Modules · joyent/node Wiki. Nodejs_resource.markdown. Impress. Impress: многоцелевой сервер приложений для Node.js. Monolithic Node.js | Richard Rodger. (99+) nodejs – Группы Google. Unix Philosophy and Node.js.