Create an account or log in

Keep learning for free! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
11 Hrs
12 Min
23 Seg

Estructura de archivos

4/38
Resources

How to start a project with Node.js?

Application development requires preparing a suitable environment. Choosing tools and understanding their installation are vital steps to achieve an effective workflow. In this article, we will explore how to start a project with Node.js, from installation to the basic structure of a project.

How to install Node.js on your system?

To begin with, we visit the official Node.js website, as here we can download the version that suits our operating system. For example, if you use a 64-bit Mac, you will be shown the optimal option for your device. The process is simple: download the installer and follow the installation steps that include several clicks on "next".

Verify the installation:

  1. Open a terminal.
  2. Run the following command to verify the version of Node.js and npm installed:
    npm -vIn
    this example, the version of npm is 6.2.0. Yours may vary, but the process is similar.

How to install Sails.js with npm?

Now that you have Node.js configured, it's time to install Sails.js, a framework that makes it easy to build web applications. Use the following command in your terminal:

npm install sails -g

The installation will depend on the speed of your Internet connection and the processing power of your computer, but it should not take more than two minutes.

Sails.js installation verification:

  1. Run:
    sails -vThe
    output will show you the version of Sails.js installed.

How to create a project structure?

With Sails.js installed, we can proceed to create the basic structure of a project. First, we need to create a directory where we will host our project. Use the following command:

mkdir platzi-right

With this command, we have created a new directory called platzi-right.

Browse and generate the Sails project:

  1. Move to the newly created directory:
    cd platzi-right
    .
  2. Generate a new project using Sails.js with the following command:
    sails new backend --no-frontend
    This will create a new Sails.js project in backend mode, avoiding generating the controlling view model (MVC) for the frontend.

How to configure and open your project?

Once the project is generated, it is time to explore its structure and configure it properly:

  1. Open your favorite text editor. This can be Atom, Visual Studio Code, or any other.
  2. Navigate to your project folder, for example, platzi-right, and select the project named backend that we just created.

The project should show folders like:

  • api: This is where you will write most of your code.
  • config: Contains default configurations adjustable according to the needs of your project.
  • node_modules: Stores the libraries needed for the application to work.

How to start the development server?

To test the configuration and operation of your development environment, you can start the Sails.js server:

  1. In the terminal, make sure you are in the backend directory.
  2. Run the command:
    sails lift
    If everything is configured correctly, you should be able to navigate to http://localhost:1337/ in your web browser. If you see the message "Cannot find", that means everything is working fine with the installation.

With these steps, you now have a basic understanding of how to start a Sails.js project with Node.js. This start will allow you to go into web development with confidence, handling each component efficiently. Continue exploring other modules and platform enhancements to enrich your programming skills.

Contributions 11

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

En windows tira este error cuando se corre el comando “sails new backend …”

"sails" no se reconoce como un comando interno o externo, 
programa o archivo por lotes ejecutable

En Mac si les aparece un EACCES error, prueben esto:

sudo npm install sails -g --unsafe-perm=true --allow-root

Para instalar sails global

npm install sails -g

Una alternativa, si como a mí no te gusta instalar cosas en el global, puede ser usar

npm i sails

Y posteriormente usar los comandos antecedidos de “npx”, ejemplo sería

npx sails lift

A mi me gusta instalar la version exacta de mis librerias, esto se hace con el flag -E

Ejemplo

npm install sails -g -E

VIM o Nano

Para los que estamos con WSL Ubuntu, tenemos que instalar con sudo

sudo npm install sails -g

Buenas noches, se crea un proyecto totalmente vacío o la opción de Web App?.

PDT:Yo uso gitbash y no tengo problemas en colocar los mismos comandos que el profe(Uso W10)

Parece que ya no sale “Not found” si no que sale esta página:

Correr nuestro proyecto

sails lift```