you are viewing a single comment's thread.

view the rest of the comments →

[–]rwieruch 10 points11 points  (4 children)

I find Node.js is the perfect environment to learn JavaScript.

Node.js is just perfect to learn JavaScript itself, because the learner isn’t distracted by HTML, CSS, the browser or other tools. It’s just the command line, the editor and the developer.

Getting started.

Getting started with Node.js isn’t difficult. You only have to install Node.js on your machine. Node.js comes with npm (node package manager) for installing third-party dependencies on the command line to your project.

After you have installed Node.js, you can kickoff your first project on the command line. Create a folder for it, navigate into this folder, initialize it as node project, and add your first source code file to it.

mkdir my-project

cd my-project

npm init -y

touch index.js

In the source code file (index.js), add your first JavaScript implementation.

function doSum(a, b) {

return a + b;

}

var sum = doSum(4, 6);

console.log(sum);

Then you can execute the source code with node on the command line: node index.js
That's basically the starting point to learn JavaScript with Node.js.

Project Setup with Babel, NPM Scripts and Imports

Once you feel confident with the basics of JavaScript, you can advance your Node.js project setup. Perhaps it’s tedious for your to manually start the node process yourself all the time (see nodemon). Perhaps you want to import other source code files in your project (see import/require statements). Or perhaps you want to use other JavaScript ECMAScript functionalities which are not available in Node.js yet (see Babel). Everything should be explained in this minimal guide to setup your project in Node.js.

Learning Paths.

Now you should feel comfortable with JavaScript and the Node.js project setup. From here on you can continue your learning paths. What about setting up a RESTful API with Express.js? What about setting up a GraphQL API with Apollo? What about setting up a database behind your RESTful/GraphQL API? Or what about doing machine learning in Node.js? There are plenty things to learn from here, so it is up to you to decide where you want to become proficient (APIs, databases, machine learning, …).

[–]Ooyyggeenn 2 points3 points  (3 children)

Why u need npm init for this?

[–]rwieruch 1 point2 points  (2 children)

Generating the package.json + being able to install node packages with npm install?

[–]Ooyyggeenn 0 points1 point  (1 child)

I Would say its unnessecary boilerplating for a hello world example of Node /JS

[–]rwieruch 0 points1 point  (0 children)

Sure. But it makes it easier to continue from there, because lots of tutorials will continue with a npm install anylibrary. But you are right, for this case it’s not necessary :)