Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does SailsJS support ES6?

Is there a way to get ES6 in sails.js?

like image 853
Jaseem Abbas Avatar asked Oct 19 '15 15:10

Jaseem Abbas


People also ask

Does Nodejs 10 support ES6?

Node js doesn't support ES6 import directly.

Is sails JS framework?

Sails is the most popular MVC framework for Node. js, designed to emulate the familiar MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with a scalable, service-oriented architecture.

What is the use of sails JS?

Sails is built on Node. js, a popular, lightweight server-side technology that allows developers to write blazing fast, scalable network appliations in JavaScript. Sails uses Express for handling HTTP requests, and wraps socket.io for managing WebSockets.


Video Answer


2 Answers

SailsJS is just a framework written via ES5 syntax and it doesn't need to support ES6.

You can write project with ES6 syntax as you usually do and use Babel\Traceur\whatever for running.

My flow is following:

  • Create Sails project;
  • Install babel as devDependencies;
  • Update npm start script in package.json with "start": "babel-node app.js";

That's it. I can write ES6\7 code in my controllers\models\etc and run the server via npm start command. It works as usual as you wrote it with ES5 syntax.

Babel Transpiler

Babel Node

like image 52
Eugene Obrezkov Avatar answered Sep 28 '22 10:09

Eugene Obrezkov


Vishnu's answer has you covered.

The explicit list of ES6 features available in the latest node release is here https://nodejs.org/en/docs/es6/

Which ES6 features ship with Node.js by default (no runtime flag required)?

  • let (strict mode only)
  • const
  • function-in-blocks (strict mode only)
    • As of v8 3.31.74.1, block-scoped declarations are intentionally implemented with a non-compliant limitation to strict mode code. Developers should be aware that this will change as v8 continues towards ES6 specification compliance.
  • Classes (strict mode only)
  • Collections
  • Map
  • WeakMap
  • Set
  • WeakSet
  • Typed arrays
  • Generators
  • Binary and Octal literals
  • Object literal extensions (shorthand properties and methods)
  • Promises
  • New String methods
  • Symbols
  • Template strings
  • Arrow Functions
like image 44
coagmano Avatar answered Sep 28 '22 10:09

coagmano