1

Inicio Api

INDEX.JS

const express = require('express');
const app = express();
const port = 3800;

app.get('/', (req,res) =>{
  res.send('hola mi server en express');
});

app.get('/nueva-ruta', (req,res) =>{
  res.send('Hola, soy una nueva ruta o endpoint');
});

app.get('/products', (req,res) =>{
  res.json({
    name: 'Product 1',
    price: 1000
  });
});

app.listen(port, () =>{
  console.log('Mi port' + port);
});

PACKAGE.JSON

{
  "name": "platzi.backend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon index.js",
    "start": "node index.js",
    "lint": "eslint"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2"
  }
}

.ESLINTRC.JSON

{
    "parserOptions": {
      "ecmaVersion": 2018
    },
    "extends": [
      "eslint:recommended",
      "prettier"
    ],
    "env": {
      "es6": true,
      "node": true,
      "jest": true
    },
    "rules": {
      "no-console": "warn"
    }
  }

Para iniciar el proyecto simplemente se debe de usar el [npm run dev]

(En caso de que salga este tipo de problema)

ERROR: npm v9.6.4 is known not to run on Node.js v14.0.0\.  This version of npm supports the following node versions: `^14.17.0 || ^16.13.0 || >=18.0.0`. You can find the latest version at https://nodejs.org/.

ERROR:
/home/andres/.nvm/versions/node/v14.0.0/lib/node_modules/npm/node_modules/hosted-git-info/lib/index.js:63#fill (template, opts) {
        ^

SyntaxError: Unexpected token '('
    at wrapSafe (internal/modules/cjs/loader.js:1101:16)
    at Module._compile (internal/modules/cjs/loader.js:1149:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Module.require (internal/modules/cjs/loader.js:1074:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object. (/home/andres/.nvm/versions/node/v14.0.0/lib/node_modules/npm/node_modules/npm-package-arg/lib/npa.js:8:19)
    at Module._compile (internal/modules/cjs/loader.js:1185:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)```

Se puede resolver con el siguiente comando

nvm install node--reinstall-packages-from=node
Escribe tu comentario
+ 2