4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cannot find module 'express'の解決法

Posted at

nodeをインストールしてプログラムを実行しようとした所、エラーが出た。

エラー文

internal/modules/cjs/loader.js:834
  throw err;
  ^

Error: Cannot find module 'express'

プログラム

app.js
const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

対処方法

expressをinstallし、パスを通す。
oh、簡単。。。

$ npm install -g express
$ export NODE_PATH=/usr/local/lib/node_modules

参考

Nodeでnode_modulesにパスを通す

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?