10 examples of 'npm install node fetch' in JavaScript

Every line of 'npm install node fetch' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
69private getNpmPath() {
70 return new Promise((resolve, reject) => {
71 which('npm', (err, npmPath) => {
72 if (err && ! npmPath) {
73 if (this.app) {
74 this.app.logger.error(`npm -> path error: ${err}`);
75 }
76 reject(err);
77 } else {
78 if (this.app) {
79 this.app.logger.log(`npm -> path: ${npmPath}`);
80 }
81 resolve(npmPath);
82 }
83 });
84 });
85}
26installNpmPackage(name: string, version: string | null | undefined, cwd: string = this.scopes.localPath) {
27 const versionWithDelimiter = version ? `@${version}` : '';
28 const cmd = `npm i --save ${name}${versionWithDelimiter}`;
29 return this.command.runCmd(cmd, cwd);
30}
9export function installNPMDependencies(ctx: BuildContext) {
10 return new Promise((resolve, reject) => {
11 exec(`npm install`, {
12 cwd: ctx.projectFolder,
13 }, (error, stdout) => {
14
15 if (error === null) {
16 resolve();
17 } else {
18 reject(Error(stdout));
19 }
20 });
21 });
22}
101async install(cwd: string) {
102 const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
103 const args = ['install'];
104 return await spawnProcess(command, args, { cwd, stdio: 'inherit' });
105}
135export function npmRun({ dir }: NpmOperationOptions, command: string): Promise {
136 return exec(dir, `npm run ${command}`);
137}
5function getLatestNodejsVersion (url, cb) {
6 var tracker = log.newItem('getLatestNodejsVersion', 1)
7 tracker.info('getLatestNodejsVersion', 'Getting Node.js release information')
8 var version = 'v0.0.0'
9 url = url || 'https://nodejs.org/dist/index.json'
10 request(url, function (e, res, index) {
11 tracker.finish()
12 if (e) return cb(e)
13 if (res.statusCode !== 200) {
14 return cb(new Error('Status not 200, ' + res.statusCode))
15 }
16 try {
17 JSON.parse(index).forEach(function (item) {
18 if (item.lts && semver.gt(item.version, version)) version = item.version
19 })
20 cb(null, version)
21 } catch (e) {
22 cb(e)
23 }
24 })
25}
4function getLatestNodejsVersion (url, cb) {
5 var tracker = log.newItem('getLatestNodejsVersion', 1)
6 tracker.info('getLatestNodejsVersion', 'Getting Node.js release information')
7 var version = ''
8 url = url || 'https://nodejs.org/dist/index.json'
9 request(url, function (e, res, index) {
10 tracker.finish()
11 if (e) return cb(e)
12 if (res.statusCode !== 200) {
13 return cb(new Error('Status not 200, ' + res.statusCode))
14 }
15 try {
16 JSON.parse(index).forEach(function (item) {
17 if (item.lts && item.version > version) version = item.version
18 })
19 cb(null, version)
20 } catch (e) {
21 cb(e)
22 }
23 })
24}
18function getNpmRemoteVersion(name: string, version: string): Promise {
19 return getPackageJson(name, {version})
20 .then((value: AbbreviatedMetadata) => {
21 return value && typeof value.version === 'string' ? value.version : undefined;
22 })
23 .catch(() => {
24 return undefined;
25 });
26}
325export function getNpmClient(config: Config, npmClient: string): Promise {
326 return new Promise(async (resolve) => {
327 if (!npmClient) {
328 if (await hasYarn(config)) return resolve('yarn');
329 exec('yarn --version', async (err, stdout) => {
330 // Don't show prompt if yarn is not installed
331 if (err || !isInteractive()) {
332 resolve('npm');
333 } else {
334 const answers = await inquirer.prompt([{
335 type: 'list',
336 name: 'npmClient',
337 message: 'Which npm client would you like to use?',
338 choices: ['npm', 'yarn']
339 }]);
340 resolve(answers.npmClient);
341 }
342 });
343 } else {
344 resolve(npmClient);
345 }
346 });
347}
9function checkNpmVersion() {
10 return new Promise((resolve, reject) => {
11 // Get npm version
12 try {
13 // remove local node_modules\.bin dir from path
14 // or we potentially get a wrong npm version
15 const newEnv = Object.assign({}, process.env);
16 newEnv.PATH = (newEnv.PATH || newEnv.Path || newEnv.path)
17 .split(path.delimiter)
18 .filter(dir => {
19 dir = dir.toLowerCase();
20 return !(dir.indexOf('iobroker') > -1 && dir.indexOf(path.join('node_modules', '.bin')) > -1);
21 })
22 .join(path.delimiter);
23
24 let timer = setTimeout(() => {
25 timer = null;
26 reject('Timeout');
27 }, 10000);
28
29 child_process.exec('npm -v', {encoding: 'utf8', env: newEnv, windowsHide: true}, (error, stdout, _stderr) => {
30 if (timer) {
31 let npmVersion = stdout;
32 clearTimeout(timer);
33 timer = null;
34 npmVersion = npmVersion.trim();
35 console.log('NPM version: ' + npmVersion);
36
37 if (gte(npmVersion, '5.0.0') && lt(npmVersion, '5.7.1')) {
38 console.warn('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
39 console.warn('WARNING:');
40 console.warn('You are using an unsupported npm version!');
41 console.warn('This can lead to problems when installing further packages');
42 console.warn();
43 console.warn('Please use "npm install -g npm@4" to downgrade npm to 4.x or ');
44 console.warn('use "npm install -g npm@latest" to install a supported version of npm!');
45 console.warn('You need to make sure to repeat this step after installing an update to NodeJS and/or npm.');
46 console.warn('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
47 process.exit(25);
48 }
49 resolve(npmVersion);
50 }
51 });
52 } catch (e) {
53 reject(e);
54 }
55 });
56}

Related snippets