evanr123
evanr123

Reputation: 75

mime.lookup() is not a function in node.js

I am trying to use the "mime" package to get the Content-Type of a file for the first time. I have run the following code in different orders through the command prompt.

First I ran the mime commands first, then ran the "node" command to open node in command prompt, I then ran the node code(this gave me the rejection: "mime.look up not a function", the other time I ran the mime commands after opening node with the node command (this seemed to get me close to success). However I am getting "Unexpected token" pointing to the "[email protected]" portion of the code. It points to the "@" symbol.

My NPM version is 6.13.4, node is 12.6.1.

Thank you.

    $ npm install mime
    npm http GET https://registry.npmjs.org/mime
    npm http 304 https://registry.npmjs.org/mime
    [email protected] node_modules/mime

    var mime = require("mime"); 
    console.log(mime.lookup("/Users/evanredmond/Desktop/winter tent.rtf"));

Upvotes: 5

Views: 16169

Answers (2)

Jatin sharma
Jatin sharma

Reputation: 324

Step 1

Change the following where the lookup is defined -

from

var charset = mime.lookup(type);

to

var charset = mime.getType(type);

Step 2 Change the following where the charsets.lookup is defined - from

 var charset = mime.charsets.lookup(type);

to

 var charset = mime.getType(type);

Upvotes: 2

mmenschig
mmenschig

Reputation: 1128

Version 2 of mime is a breaking change to version 1, where

.lookup() renamed to .getType()

Either install mime version 1, or try using the updated function Npm documentation on mime: https://www.npmjs.com/package/mime

If you'd like to use .lookup(), then you should run:

npm uninstall mime
npm install mime@^1

Upvotes: 17

Related Questions