'np' не распознается как внутренняя или внешняя команда в nodejs во время выполнения внутреннего кода - PullRequest
0 голосов
/ 09 января 2019

Я пытаюсь запросить данные из API WordPress, используя graphql и node-fetcher, но каждый раз, когда запускаю свой бэкэнд-код, выдается какая-то ошибка, подобная этой.

npm run start-back-dev

> p4d1-again@0.1.0 start-back-dev C:\Users\adity\Desktop\live-coding\p4d1-again
> nodemon --watch server/*.js ./server/server.js

[nodemon] 1.18.9
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: server/*.js
[nodemon] starting `concurrently 'npm run start-front' 'npm run start-back-dev' ./server/server.js`
[0] 'np' is not recognized as an internal or external command,
[0] operable program or batch file.
[1] 'run' is not recognized as an internal or external command,
[1] operable program or batch file.
[2] 'start-front'' is not recognized as an internal or external command,
[2] operable program or batch file.
[3] 'np' is not recognized as an internal or external command,
[3] operable program or batch file.
[4] 'run' is not recognized as an internal or external command,
[4] operable program or batch file.
[5] 'start-back-dev'' is not recognized as an internal or external command,
[5] operable program or batch file.
[6] '.' is not recognized as an internal or external command,
[6] operable program or batch file.
[5] start-back-dev' exited with code 1
[4] run exited with code 1
[3] np exited with code 1
[2] start-front' exited with code 1
[1] run exited with code 1
[0] np exited with code 1
[6] ./server/server.js exited with code 1
[nodemon] app crashed - waiting for file changes before starting...

package.json

"scripts": {
    "start-front": "react-scripts start",
    "start-back-dev": "nodemon --watch server/*.js ./server/server.js",
    "start-back": "node ./server/app.js",
    "start": "concurrently 'npm run start-front' 'npm run start-back-dev'",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Сервер / app.js

const express = require('express');
const bodyParser = require('body-parser');
const fetch = require('node-fetch')
const HttpLink = require('apollo-link-http');
const {graphqlExpress, graphiqlExpress} = require('apollo-link-http');
const app = express();


const fetcher = async({query, variables, operationName, context}) => {
    const fetchResult = await fetch(
        'http://localhost/wordpress/graphql',
        {
            method: 'POST',
             headers: {
                // 'Content-Type': 'application/json'
                /* MAKE AUTHORIZATION SOMEHOW for the wordpress */
                /* GO WITH JWT OR OAUTH 2.0. OAUTH 2.0 Recommended */
                //  'Authentication': `Bearer ${context.authKey}`,
        },
        body: JSON.stringify({query, variables, operationName})
        }
    )
    return fetchResult.json();
}


app.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql'
}) 
)

introspectSchema (fetcher) .then (схема => { const gqlschema = makeRemoteExecutableSchema ({ схемы, Fetcher }) app.use ('/ graphql', bodyParser.json (), graphqlExpress ({schema: gqlschema})) })

app.listen (4000, () => console.log ('приложение работает на порту 4000'));

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...