Your Choice JavaScript News

Node News Sunday, February 11

Node News TLDR / Table of Contents

  • Passport Authentication for Node.js Applications
    • This article shows how Passport is used to add Facebook and GitHub authentication to a Node.js application.
    • app, facebook app, github app, Facebook Authentication, node app
  • Forms, File Uploads and Security with Node.js and Express —
    • Mark Brown shows how to use Node.js and Express to process form data and handle file uploads, covering validation and security security issues.
    • validation errors, Handling form data, simple contact form, email address, popular web framework
  • An Exhaustive Guide to Writing Dockerfiles for Node.js Web Apps
    • Step by step guide to writing highly optimized Dockerfiles for Node.js web app development and deployment. Covers adding hot reloading, serving static files and using multi-stage alpine builds.
    • docker, Node.js Docker Best, nginx docker, node express server,
  • Getting Node.js Testing and TDD Right | @RisingStack
    • In this in-depth tutorial we discuss how you can do TDD (test-driven development) the right way; and how you should approach testing Node.js applications.
    • new module, test, test case, tests, proper test coverage
  • What is the Haskell response to Node.js?
    • I believe the Erlang community is not envious of Node.js as it does non-blocking I/O natively and has ways to scale deployments easily to more than one processor (something not even built-in in Node.js). More details at http://journal.dedasys.com/2010/04/29/erlang-vs-node-js and Node.js or Erlang
    • haskell, threads, OS threads, node.js, Snap Haskell Web
  • JavaScript Clean Coding Best Practices | @RisingStack
    • This post covers general clean coding guidelines for naming and using variables & functions, as well as some JavaScript specific clean coding best practices
    • clean coding, clean code, best practices, specific clean coding, variable names
  • How to increase React performance: React 16, Next.js and Node 8.x LTS
    • In this brief article we will go through some of the key latest improvements in React, Next.js and Node.js. These improvements are all related, as Next.js is the framework for server-side rendered…
    • key latest improvements, high performance web, server-side rendered React, server-side rendering, performance web applications

Score: 509.8701908288237
URL: https://www.sitepoint.com/passport-authentication-for-nodejs-applications/
Tweeted At: Sat Feb 10 20:55:09 +0000 2018
Publish Date: 2018-02-05T17:00:40+00:00
Author:

  • Create a file index.js in the root folder of your app and add the following content to it: – /* EXPRESS SETUP */ – – const express = require(‘express’); – const app = express(); – – app.get(‘/’, (req, res) = res.sendFile(‘auth.html’, { root : __dirname})); – – const port =…
  • Add the following code at the bottom of the index.js file: – /* PASSPORT SETUP */ – – const passport = (req, res) = res.send(“You have successfully logged in”)); – app.get(‘/error’, (req, res) = res.send(“error logging cb) { – cb(null, cb) { – cb(null, obj); – }); – – Here…
  • Add the following code at the bottom of your index.js file: – /* FACEBOOK AUTH */ – – const FacebookStrategy = FACEBOOK_APP_ID = ‘your app id’; – const FACEBOOK_APP_SECRET = ‘your app secret’; – – passport.use(new FacebookStrategy({ – clientID: FACEBOOK_APP_ID, – clientSecret: FACEBOOK_APP_SECRET, – callbackURL: “/auth/facebook/callback” – }, – function(accessToken,…
  • Lastly, set the Valid OAuth redirect URIs field to you start the app now and click the Sign in with Facebook link, you should be prompted by Facebook to provide the required information, and after you’ve logged in, you should be redirected to the /success route, where you’ll see the…
  • First, we’ll install the passport-github module: – npm install passport-github –save – – Now go to the index.js file and add the following lines at the bottom: – /* GITHUB AUTH */ – – const GitHubStrategy = GITHUB_CLIENT_ID = “your app id” – const GITHUB_CLIENT_SECRET = “your app secret”; -…

Tags: app, facebook app, github app, Facebook Authentication, node app

Score: 388.96171101350643
URL: https://www.sitepoint.com/forms-file-uploads-security-node-express/
Tweeted At: Sat Feb 10 17:26:06 +0000 2018
Publish Date: 2018-02-06T00:15:57+00:00
Author:

  • // routes.js – const express = require(‘express’) – const router = (req, res) = { – = router – – Displaying the Form – When people make a GET request to /contact, we want to render a new view contact.ejs: – // (req, res) = { – res.render(‘contact’) – })…
  • ejs — – div class=”form-header” – h2Send us a message/h2 – /div – form method=”post” action=”/contact” novalidate – div class=”form-field” – label for=”message”Message/label – textarea class=”input” id=”message” name=”message” rows=”4″ autofocus/textarea – /div – div class=”form-field” – label for=”email”Email/label – input class=”input” id=”email” name=”email” type=”email” value=”” / – /div – div…
  • If invalid, we need to pass back the submitted values to the view so they don’t need to re-enter them along with any error messages we want to (req, res) = { – res.render(‘contact’, { – data: {}, – errors: {} – }) – }) – – router.post(‘/contact’, (req, res)…
  • There are three middlewares we need to include to wire this up: – const cookieParser = require(‘cookie-parser’) – const session = flash = middlewares = [ – // … – cookieParser(), – session({ – secret: ‘super-secret-key’, – key: ‘super-secret-cookie’, – resave: false, – saveUninitialized: false, – cookie: { maxAge: 60000…
  • errors.isEmpty()) { – return res.render(‘contact’, { – data: req.body, – errors: errors.mapped() – }) – } – – const data = matchedData(req) – console.log(‘Sanitized: ‘, data) – // Homework: send sanitized data in an email or persist in a db – – req.flash(‘success’, ‘Thanks for the message!

Tags: validation errors, Handling form data, simple contact form, email address, popular web framework

Score: 269.37552730516114
URL: https://blog.hasura.io/an-exhaustive-guide-to-writing-dockerfiles-for-node-js-web-apps-bbee6bd2f3c4?gi=6befa7288038
Tweeted At: Thu Feb 08 09:00:35 +0000 2018
Publish Date: 2018-02-07T13:18:51.883000+00:00
Author: Praveen Durairaj

  • Using nodemon for hot reloading during development.Optimising for Docker cache layers — placing commands in the right order so that npm install is executed only when necessary.Serving static files (bundles generated via React/Vue/Angular) using serve package.Using multi-stage alpine build to reduce final image size for production.
  • Simple Dockerfile ExampleFor the base image, we have used the latest LTS versionnode:carbonDuring image build, docker takes all files in the context directory.
  • If any files change, nodemon will automatically restart your node application.We’ll build the image and run nodemon so that the code is rebuilt whenever there is any change inside the app directory.
  • OptimisationsIn your Dockerfile, prefer COPY over ADD unless you are trying to add auto-extracting tar files, according to Docker’s best practices.Bypass package.json ‘s start command and bake it directly into the image itself.
  • Assuming you are building a UI app using React/Vue/Angular, you would ideally build your final bundle using npm run build which would generate a minified JS and CSS file.The other alternative is to either 1) build the files locally and use an nginx docker to serve these static files or…

Tags: docker, Node.js Docker Best, nginx docker, node express server,

Score: 260.2015296367113
URL: https://blog.risingstack.com/getting-node-js-testing-and-tdd-right-node-js-at-scale/
Tweeted At: Sun Feb 11 14:00:52 +0000 2018
Publish Date: 2017-02-14T17:06:54+00:00
Author: Peter Czibik

  • And install the tools required for testing – – Don’t forget to add the following lines to the package json – – Let’s create the first test file for our module: – – I always like to create a function called “up” to that encapsulates the creation of the table….
  • When I’m dealing with testing modules with a database, I usually create an extra describe block for those functions that need test data inserted.
  • This paradigm can also be applied if you don’t want your functions to call the database, you can stub out all of the functions one by one on the db object like this: – – As you can see, it is already a bit tedious work to restore all of…
  • Check out how easy it is: – – To take it an additional step further you can move the sandbox creation in a block: – – There is one last refactor to take on these tests, instead of stubbing each property on the fake object, we can use a mock…
  • Your last assignment is to go and fill your codebase with the knowledge you have learned and create greatly-documented test cases for your code in TDD style!

Tags: new module, test, test case, tests, proper test coverage

Score: 169.0375874547648
URL: https://stackoverflow.com/questions/3847108/what-is-the-haskell-response-to-node-js
Tweeted At: Sat Feb 10 21:48:00 +0000 2018
Publish Date:
Author:

  • First up, I don’t hold your view that node.js is doing the right thing exposing all of those callbacks.
  • So with this in mind, you can write using a asynchronous style if you so wish, but by doing so you’d miss out on writing in an efficient synchronous style, with one thread per request.
  • Haskell is ludicrously efficient at synchronous code, especially when compared to other languages.
  • When you write code that has to communicate with other threads, it’s very simple to make it threadsafe thanks to haskell’s concurrency primitives.
  • You have no such problems, ghc will distribute your work amongst real OS threads.

Tags: haskell, threads, OS threads, node.js, Snap Haskell Web

Score: 134.91931166347993
URL: https://blog.risingstack.com/javascript-clean-coding-best-practices-node-js-at-scale/
Tweeted At: Sun Feb 11 05:06:08 +0000 2018
Publish Date: 2016-12-13T12:41:08+00:00
Author: András Tóth

  • Writing clean code is what you must know and do in order to call yourself a professional developer.
  • In this blog post, we will cover general clean coding principles for naming and using variables & functions, as well as some JavaScript specific clean coding best practices.
  • When you are doing code reviews with your fellow developers, these names are easier to reference.
  • A function name should be a verb or a verb phrase, and it needs to communicate its intent, as well as the order and intent of the arguments.
  • In the first place, you should write clean code, then use profiling to find performance bottlenecks.

Tags: clean coding, clean code, best practices, specific clean coding, variable names

Score: 100.64766990291261
URL: https://medium.com/graphql-mastery/high-performance-web-react-16-next-js-and-node-8-x-lts-dba86a25f438
Tweeted At: Tue Jan 02 16:42:39 +0000 2018
Publish Date: 2018-01-02T14:01:03.313000+00:00
Author: David Mráz

  • The React 16 (fiber) has been released; long-term support for Node.js LTS has been added to version 8; and the Next.js framework for server-side rendered React apps has come to version 4, and is intended for use with React 16.
  • In this brief article we will go through some of the key latest improvements in React, Next.js and Node.js.
  • These improvements are all related, as Next.js is the framework for server-side rendered React apps; React 16 has massive improvements on server-side rendering, and performs much better if you use the latest versions of Node.js.
  • In this brief article we will go through some of the key latest improvements of React.js, Next.js and Node.js, and for those who want to have a quick start we will also introduce my high performance starter kit.React 15 vs React 16Some of these key improvements are:Render does not need to…
  • The key feature of Next.js version 4 is the added support for React 16.

Tags: key latest improvements, high performance web, server-side rendered React, server-side rendering, performance web applications

Top Node Courses

The Complete Node.js Developer Course (2nd Edition) (60,232 students enrolled)

By Andrew Mead
  • Build, test, and launch Node apps
  • Create Express web servers and APIs
  • Store data with Mongoose and MongoDB
  • Use cutting-edge ES6/ES7 JavaScript
  • Deploy your Node apps to production
  • Create real-time web apps with SocketIO

Learn more.


Angular (Angular 2+) & NodeJS - The MEAN Stack Guide (26,806 students enrolled)

By Maximilian Schwarzmüller
  • Build real Angular + NodeJS applications
  • Understand how Angular works and how it interacts with Backends
  • Connect any Angular Frontend with a NodeJS Backend
  • Use MongoDB with Mongoose to interact with Data on the Backend
  • Use ExpressJS as a NodeJS Framework
  • Provide a great user experience by using Optimistic Updating on the Frontend
  • Improve any Angular (+ NodeJS) application by adding Error Handling

Learn more.