LoginSignup
1
1

More than 1 year has passed since last update.

【npm】json-serverが起動できない

Posted at

 やろうとしたこと

SPAを1から作ってみたく、まずはモックAPIを構築したいと思い、json-serverなる30秒でモックを構築できるものがあると知り、使ってみました。

※下記参照
https://github.com/typicode/json-server

今回はグローバルにはインストールしたくなかったので、ローカルインストールしました。

$ npm install json-server

(色々、手順は端折っていますが)次に、json-serverを起動させるコマンドをpackage.jsonのscriptに書きました。

  "scripts": {
      "json-server": "json-server --watch db.json"
  },

db.jsonの中身は、DBそのものです。

json-serverを起動する

準備が整ったので、いざ起動すべく下記コマンドを叩きました。

$ npm json-server

すると、こんなメッセージがでました。

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

npmの使い方を教えてくれました…

正しくは、

$ npm run json-server

でした。

今まで深く意識しないでnpm run してましたが、勉強になりました。
長いコマンド書かなくて良くなるので、結構便利なんですね。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1